Results 1 to 8 of 8

Thread: Run executable from within C++/Qt

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    Join Date
    Aug 2009
    Posts
    122
    Thanks
    74
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Run executable from within C++/Qt

    Dear Santosh,

    Thanks again.
    The below code makes a QString that is empty as this does not print anything on the screen

    Qt Code:
    1. QObject *parent;
    2. QString program = "./ent";
    3. QStringList arguments;
    4. arguments << "-b" << "-t" << "input.txt";
    5.  
    6. QProcess *myProcess = new QProcess(parent);
    7. myProcess->start(program, arguments);
    8.  
    9.  
    10. if(myProcess->waitForStarted(5000))
    11. {
    12. QByteArray out_data = myProcess->readAllStandardOutput();
    13. QString out_string(out_data);
    14. qDebug() << out_string.toStdString().c_str();
    15. cout << "results: " << out_string.toLocal8Bit().constData() << "\n";
    16. }
    17. else
    18. {
    19. qDebug() << "myProcess did not start in time";
    20. }
    To copy to clipboard, switch view to plain text mode 

    I know that the other program works because this gives me the correct answer:
    Qt Code:
    1. system("./ent -b -t input.txt");
    To copy to clipboard, switch view to plain text mode 
    Do you advise against using the latter version?
    Last edited by timmu; 3rd January 2013 at 10:13.

Similar Threads

  1. Could not find executable
    By jeff28 in forum Qt Quick
    Replies: 6
    Last Post: 31st August 2012, 14:49
  2. run a executable file
    By Ali Reza in forum Newbie
    Replies: 4
    Last Post: 17th June 2012, 20:09
  3. QT + SQL + executable
    By anouar2002 in forum Newbie
    Replies: 1
    Last Post: 22nd January 2012, 22:56
  4. Help in the executable
    By mukunda in forum Qt Programming
    Replies: 6
    Last Post: 5th July 2011, 07:59
  5. Static Executable
    By perseo in forum Qt Programming
    Replies: 1
    Last Post: 20th May 2008, 21:39

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.