PDA

View Full Version : QProcess problem



Mystical Groovy
2nd December 2008, 12:13
Hey all,
I have a strange problem with QProcess, I use QProcess and system command "whoami" to get current logged in user.




/** where "user" is the QLabel"**/
QString whoamiCom = "/usr/bin/whoami"; //i also tried with just "whoami"
QProcess *userproc = new QProcess(this);
userproc->start(whoamiCom);

user->setText(userproc->readAllStandardOutput());
/**I also tried using this method:
QByteArray result = userproc->readAll();
user->setText(result); **/

in anyway the program compiles and runs but nothing is parsed on "user" Label.

Please help, thx :cool:

caduel
2nd December 2008, 13:50
You have to wait for the command to complete, before parsing the (in your case not yet printed) output. (see QProcess::waitForFinished())
(Unlike system() QProcess by nature is asynchronous: the command is executed and your program continues running.)

HTH

Mystical Groovy
2nd December 2008, 20:07
thx my friend, problem solved :)