QT + system command
-
Hi all,
I am trying to trigger a command "sudo apt-get install --only-upgrade [mysoftware]" in qt so that the linux will update my software when i click update manually.
Following is piece of code thats not working :
void MainWindow:: on_whichos_clicked()
{
QMessageBox msgBox;msgBox.setWindowTitle("Which OS ?");
#ifdef Q_OS_LINUX
QProcess process;process.start("sudo apt-get", QStringList() << "install setserial" ); msgBox.setInformativeText("This is Linux OS :)");__
Above code works if the process is gui based but the apt-get or any other shell based process does not work. I am trying to do same thing on windows and mac for my auto update feature.
-
You could make a separate thread and use system() call in that thread
-
Hi, AFAIK, QProcess works for all the cases in mentioned.
Please note that, if you want to run bash command, the program you started is the bash instead of the bash command. If you run some command such as "sudo apt-get ...", the command is sudo.
-
You can try popen() with write only flag, so you dont have to use another thread (like with system()).
-
@process.start(“sudo apt-get”, QStringList() << “install setserial” ); @
should read
@process.start(“sudo", QStringList() << "apt-get” << “install" << "setserial” );@
There is no command on your system called "sudo apt-get". Commands containing spaces are legal, but tend to be avoided on Linux.
-
Hi,
In addition to what Tobias wrote, you will also need a mean to ask the user for it's password i.g. using the -A option
-
Hi,
I am trying to use QT process as;
// Create QProcess object
proc = new QProcess();
proc->start("ping", QStringList() << "-c 10" << QString(www.google.com));And I am gettig error as;
ping: Invalid number '10'
Any help please,
Kind Regards