android - 如何使用 Qt Creator 运行 ADB 命令?

标签 android c++ bash qt adb

目前我正在尝试在 Qt 中获取一个按钮来运行以下命令:adb reboot。我在 MAC 上,当我在我的控制台中运行此命令时,它会重新启动通过 USB 连接到我的计算机的 Android 设备。我看了网上的论坛,一直无法解决这个问题。以下是我在 Qt 中尝试调用 adb reboot 时的一些尝试:

void MainWindow::on_pushButton_clicked()
{
    QProcess::startDetached("/bin/bash", QStringList()<< "-c" << "export PATH=${PATH}:/Downloads/adt-bundle-mac-x86_64-20140702/sdk/platform-tools/");
    QProcess::startDetached("/bin/bash", QStringList()<< "-c" << "adb reboot");
    QProcess::startDetached("/bin/sh", QStringList()<< "-c" << "adb reboot");
    QProcess::startDetached("/Downloads/adt-bundle-mac-x86_64-20140702/sdk/platform-tools/", QStringList()<< "-c" << "adb reboot");
}

这是我点击按钮时控制台的输出:

Starting /Users/ddelorenzo/Documents/QaGUI/QaGUI/QaGUI.app/Contents/MacOS/QaGUI..
/bin/bash: adb: command not found
/bin/sh: adb: command not found

任何帮助将不胜感激!

最佳答案

最简单的方法是使用 this method :

bool QProcess::startDetached(const QString & command) [static]

This is an overloaded function.

Starts the command command in a new process, and detaches from it. Returns true on success; otherwise returns false.

Argument handling is identical to the respective start() overload.

After the command string has been split and unquoted, this function behaves like the overload which takes the arguments as a string list.

因此,我会这样写:

if (!QProcess::startDetached("/Downloads/adt-bundle-mac-x86_64-20140702/sdk/platform‌​-tools/adb reboot"))
    qDebug() << "Failed to execute";

关于android - 如何使用 Qt Creator 运行 ADB 命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26553878/

相关文章:

android - Gradle位置不正确如何解决Android Gradle错误

java - 最大化多个桶的总和?

c - (Linux, C) 两个线程,屏幕上有两个独立的文本窗口,怎么办?

linux - 将输入从一个 shell 传递到另一个 shell,然后再次返回输入

java - android.media.AudioRecord;错误

android - 将android模块上传到bintray并链接到jcenter

c++ - std::initializer_list 和 std::make_shared: 参数太多...预期 3 提供 0

c++ - 将子窗口添加到分层窗口

linux - 在 Fedora 上运行远程根脚本

java - API 23 本地位置不可用