How do you run ADB commands with Qt Creator?

I am currently trying to get the button in Qt to run the following command: adb reboot

. I am on a MAC and when I run this command on my console it reboots the device Android

connected to my computer via USB

. I have been reading online forums and have been unable to resolve this issue. Here are some of my attempts when called adb reboot

in Qt:

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");
}

      

This is the output from my console when I click the button:

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

      

Any help would be greatly appreciated!

+3


source to share


1 answer


The easiest way is to use this method :

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

This is an overloaded function.

Launches a command command in a new process and distracts from it. Returns true on success; otherwise it returns false.

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

After the command line has been split and unquoted, this function behaves like an overload that takes arguments as a list of strings.



So I would write something like this:

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

      

0


source







All Articles