gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 15:01:11 25 4
gpt4 key购买 nike

目前我正在尝试在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com