Results 1 to 4 of 4

Thread: [QProcess] Calling console program

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [QProcess] Calling console program

    navi(avatar) is right ... u can get the readAllStandardOutput() or readAllStandardError() only after the QProcess emits readyRead() signal .. be sure u are receiving std output or std error ... so wait till u receives the signal readyReadStandardOutput() or readyReadStandardError() ..
    "Behind every great fortune lies a crime" - Balzac

  2. #2
    Join Date
    Feb 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [QProcess] Calling console program

    Ok, I still am doing something wrong, but I took the advice both of you presented me. When I click my button, which invokes my command-line based program, it does the following:

    Qt Code:
    1. QString program = "/home/bgarrison/code/myUtils";
    2. QStringList arguments;
    3.  
    4. myProcess = new QProcess(this);
    5.  
    6. connect (myProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(printOutput()));
    7. connect (myProcess, SIGNAL(readyReadStandardError()), this, SLOT(printError()));
    8.  
    9. myProcess->start(program, arguments);
    10.  
    11. myProcess->waitForFinished();
    To copy to clipboard, switch view to plain text mode 

    printOutput() is a private SLOT in my class and it does the following:

    Qt Code:
    1. void cMyUtils::printOutput()
    2. {
    3. ui->e_Log->append("Got to printOutput()"); // TextEdit to see results
    4.  
    5. QByteArray byteArray = myProcess->readAllStandardOutput();
    6. QStringList strLines = QString(byteArray).split("\n");
    7.  
    8. foreach (QString line, strLines){
    9. ui->e_Log->append(line);
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void Dialog_FileSplitter::printError()
    2. {
    3. ui->e_Log->append("Got to printError()");
    4.  
    5. QByteArray byteArray = myProcess->readAllStandardError();
    6. QStringList strLines = QString(byteArray).split("\n");
    7.  
    8. foreach (QString line, strLines){
    9. ui->e_Log->append(line);
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    This resulted in me being able to see why the program was not starting :)

    Got to printError()
    /home/bgarrison/code/myUtils: error while loading shared libraries: libboost_regex.so.1.41.0: cannot open shared object file: No such file or directory
    Looks like I have a problem linking the Boost libraries, not calling the program using QProcess. Thanks for all of your help!

Similar Threads

  1. how to print a matrix to a console in GUI program
    By elflord in forum Qt Programming
    Replies: 2
    Last Post: 14th March 2009, 12:16
  2. QProcess-startDetached and Console screen problem
    By ramazangirgin in forum Qt Programming
    Replies: 1
    Last Post: 17th June 2008, 08:05
  3. QProcess start a console program
    By Shawn in forum Qt Programming
    Replies: 2
    Last Post: 9th November 2007, 12:38
  4. QProcess and console programs
    By bond_e in forum Qt Programming
    Replies: 10
    Last Post: 13th July 2007, 08:39
  5. Console Program Problem
    By ball in forum Qt Programming
    Replies: 9
    Last Post: 28th May 2006, 09:05

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
  •  
Qt is a trademark of The Qt Company.