Results 1 to 3 of 3

Thread: QProcess problem

  1. #1
    Join Date
    Sep 2008
    Posts
    43
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QProcess problem

    Hey all,
    I have a strange problem with QProcess, I use QProcess and system command "whoami" to get current logged in user.

    Qt Code:
    1. /** where "user" is the QLabel"**/
    2. QString whoamiCom = "/usr/bin/whoami"; //i also tried with just "whoami"
    3. QProcess *userproc = new QProcess(this);
    4. userproc->start(whoamiCom);
    5.  
    6. user->setText(userproc->readAllStandardOutput());
    7. /**I also tried using this method:
    8.   QByteArray result = userproc->readAll();
    9. user->setText(result); **/
    To copy to clipboard, switch view to plain text mode 

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

    Please help, thx

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QProcess problem

    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

  3. #3
    Join Date
    Sep 2008
    Posts
    43
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QProcess problem

    thx my friend, problem solved

Similar Threads

  1. QProcess and kfmclient exec problem
    By ramazangirgin in forum Qt Programming
    Replies: 5
    Last Post: 6th June 2008, 08:31
  2. QProcess problem (Main program hangs)
    By sincnarf in forum Qt Programming
    Replies: 5
    Last Post: 11th October 2007, 09:26
  3. QThread and QProcess problem
    By codebehind in forum Qt Programming
    Replies: 13
    Last Post: 7th August 2007, 08:11
  4. Quoting problem with QProcess
    By the_bis in forum Qt Programming
    Replies: 1
    Last Post: 15th December 2006, 11:24
  5. problem with qprocess
    By deekayt in forum Qt Programming
    Replies: 2
    Last Post: 13th June 2006, 13:30

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.