PDA

View Full Version : [Solved]I can't make QProcess work



Nirvana
22nd January 2016, 18:49
I am trying to get a Linux console output. Here is my code


p.start("gsettings get org.gnome.desktop.wm.preferences theme");
QString p_stdout = p.readAllStandardOutput();
p.waitForFinished();
qDebug()<<"theme ="<<p_stdout;

in terminal, I get Ambiance output which is my current theme. But QT terminal gives theme ="" output.
What am I doing wrong?
Thanks

ChrisW67
22nd January 2016, 20:46
You are reading all available output before the program is run. The program does not actually start until your code reaches an event loop, either the main one or the one provided by waitForFinished(). Swap line 2 and 3.

Nirvana
22nd January 2016, 21:40
Thank you! It does work now.

anda_skoa
23rd January 2016, 10:14
And the command should be "gsettings", the other strings should be the command's arguments as a QStringList.

Cheers,
_