Results 1 to 8 of 8

Thread: Trying to use QProcess

  1. #1
    Join Date
    Oct 2009
    Posts
    22
    Thanks
    2
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Question Trying to use QProcess

    Hi again,

    Just wondering if anyone would mind having a look at an issue I am having and maybe point out where I am going wrong.

    I have created a simple widget with a push button it Qt Designer, I have created Signals and Slots, clicked() and process_started() respectively. I am trying to run another Qt application when the push button is pressed.

    However I keep getting compile errors which I cannot seem to resolve, so hopefully a fresh pair of eyes may be able to assist.

    mainwindow.cpp:19: error: ISO C++ forbids declaration of ‘process_started’ with no type
    mainwindow.cpp:19: error: prototype for ‘int mainwindow:rocess_started()’ does not match any in class ‘mainwindow’
    mainwindow.h:25: error: candidate is: void mainwindow:rocess_started()
    Qt Code:
    1. class mainwindow : public QMainWindow
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. mainwindow();
    7. QProcess *process;
    8.  
    9. public slots:
    10. void process_started();
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. mainwindow::mainwindow()
    2. {
    3. process = new QProcess();
    4. widget.setupUi(this);
    5. }
    6.  
    7. mainwindow::process_started()
    8. {
    9. process->start("./home/i386-qt-rss");
    10. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication app(argc, argv);
    4. mainwindow w;
    5. w.show();
    6. return app.exec();
    7. }
    To copy to clipboard, switch view to plain text mode 

    Thanks very much for having look.

    HS

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Trying to use QProcess

    you forgot to add forward declaration for QProcess class
    Qt Code:
    1. ...
    2. class QProcess;
    3. class mainwindow : public QMainWindow
    4. {
    5. ...
    6. };
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Trying to use QProcess

    also, you forgot to specify type for function
    Qt Code:
    1. void mainwindow::process_started()
    2. {
    3. process->start("./home/i386-qt-rss");
    4. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  4. #4
    Join Date
    Oct 2009
    Posts
    22
    Thanks
    2
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Trying to use QProcess

    Quote Originally Posted by spirit View Post
    also, you forgot to specify type for function
    Qt Code:
    1. void mainwindow::process_started()
    2. {
    3. process->start("./home/i386-qt-rss");
    4. }
    To copy to clipboard, switch view to plain text mode 
    You know something, I am sitting here looking at some example code and I don't know how I missed that, once you pointed it out I gave my forehead a bloody hard slap.

    Thanks very much.

  5. #5
    Join Date
    Oct 2009
    Posts
    22
    Thanks
    2
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Trying to use QProcess

    Just to add, this has now compiled, however I thought the app the process is linked to would have started and opened up. I can see that there hass been a thread created when I click the pushbutton but nothing appears on screen. Is this normal?

  6. #6
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Trying to use QProcess

    if you need call program in a new process use QProcess::startDetached. in this case you will see a separate window.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  7. The following user says thank you to spirit for this useful post:

    hybrid_snyper (20th October 2009)

  8. #7
    Join Date
    Oct 2009
    Posts
    22
    Thanks
    2
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Trying to use QProcess

    So I take it once startDetached is called then the first application is not aware of the second, ie when the launched app has finished and has been cloased?

  9. #8
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Trying to use QProcess

    it depends on how it works.
    if you need to know when this app will stopped then you should use QProcess::start and handle signals QProcess::started & QProcess::finished.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

Similar Threads

  1. Detect First QProcess finished in a group and kill other
    By Davidaino in forum Qt Programming
    Replies: 3
    Last Post: 11th July 2008, 12:53
  2. QProcess exitStatus()
    By user_mail07 in forum Qt Programming
    Replies: 2
    Last Post: 12th June 2008, 20:51
  3. QProcess and Pipes
    By KaptainKarl in forum Qt Programming
    Replies: 1
    Last Post: 9th April 2007, 23:11
  4. QProcess extremely slow on Windows?
    By Pepe in forum Qt Programming
    Replies: 2
    Last Post: 26th March 2007, 00:25
  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.