Results 1 to 12 of 12

Thread: QProcess::finished()

  1. #1
    Join Date
    May 2008
    Posts
    15
    Thanks
    1

    Default QProcess::finished()

    Hi

    How do I connect signal finished() from QProcess?
    It is not working, but connect() returns true.

    Qt Code:
    1. QProcess* app = new QProcess();
    2. // app params setzen
    3. ...
    4.  
    5. // slot connect
    6. connect(app,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(AppFinished()));
    To copy to clipboard, switch view to plain text mode 


    Thanks in advance,
    Mike
    Last edited by jpn; 8th July 2008 at 17:53. Reason: changed [qtclass] to [code] tags

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

    Default Re: QProcess::finished()

    looks good.
    How do you tell it's not working?

    And please show us more code.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess::finished()

    How do you start the process? Make sure you don't use any static methods.

  4. #4
    Join Date
    May 2008
    Posts
    15
    Thanks
    1

    Default Re: QProcess::finished()

    My goal is to achieve the following use case and I believe i missunderstood the usage of QProcess?

    My QT program is starting another program with a given filename, example: word.exe and file.doc or the one mentioned in the code. My Qtprogram shouldnt freeze while the other program is activ. Then I want to know, if the user has exited the other program so i can take care of the newly edited doc file...

    Qt Code:
    1. QProcess* app = new QProcess();
    2. // app params
    3. args.push_back(Filename().c_str()); // Filename coming from somewhere else looking like this "C:\someplace\file.mm"
    4. app->start("c:\\Programme\\Freemind\\Freemind.exe",args);
    5.  
    6. // slot connect
    7. connect(app,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(AppFinished()));
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess::finished()

    Quote Originally Posted by T1c4L View Post
    app->start("c:\\Programme\\Freemind\\Freemind.exe",arg s);

    // slot connect
    connect(app,SIGNAL(finished(int,QProcess::ExitStat us)),this,SLOT(AppFinished()));
    You should make the connection before starting the process to avoid race condition.

    What happens if you add the line below?
    Qt Code:
    1. connect( app, SIGNAL( started() ), qApp, SLOT( about() ) );
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    May 2008
    Posts
    15
    Thanks
    1

    Default Re: QProcess::finished()

    hey jacek!

    placing the connect before the start() did the trick! its working now, i tested it with notepad, tomorrow i will test it with the freemind program.

    I have another question , Before QProcess i tested a lil bit with QDesktopServices... and with openurl i was able to lauch a ".mm" file. it was automatically loaded within the apropriate Freemind Tool.

    Is it possible to retrieve the location of the freemind.exe ? without searching the entire hdd for it? as you can see the freemind.exe was hardcoded in my previous post. Thats a bad thing we both know it ^^. Any hint for that?

    im using STL c++ and QT 4.3.4

  7. #7
    Join Date
    May 2008
    Posts
    15
    Thanks
    1

    Default Re: QProcess::finished()

    Hi Jacek,

    the code is not working, it worked with notepad but somehow its not working =(

    please take a look:

    Qt Code:
    1. args.push_back(filename);
    2. m_MindMapApp = new QProcess();
    3. connect(m_MindMapApp,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(testv()));
    4. m_MindMapApp->start("c:\\Programme\\FreeMind\\Freemind.exe", args);
    To copy to clipboard, switch view to plain text mode 

    testv() slot isnt called once..

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

    Default Re: QProcess::finished()

    * does your program get started (a window pops up)?
    * if not or unsure:
    * is the path to your exe correct?
    * call waitForStarted() and print the exitCode() to stderr to see if the programm gets executed
    * did connect return true?

  9. #9
    Join Date
    May 2008
    Posts
    15
    Thanks
    1

    Default Re: QProcess::finished()

    connect returns true,

    the application freemind which im trying to start is open and the file is been loaded too.

    But my slot wont be accessed after closing the freemind application.

  10. #10
    Join Date
    May 2008
    Posts
    15
    Thanks
    1

    Default Re: QProcess::finished()

    ok guys! i found the true source of the problem.

    the connect n everything is working fine when i use it with winamp, notepad or vlc.

    But the Freemind program doesnt! Its only emiting finished() after i started the application but not after quiting it!


    The difference between freemind the other tools is, freemind needs Java virtual machine..could that be a problem for QProcess?

    any ideas how to solve this problem?

  11. #11
    Join Date
    May 2008
    Posts
    15
    Thanks
    1

    Default Re: QProcess::finished()

    please help me :-(


    ^^

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess::finished()

    Quote Originally Posted by T1c4L View Post
    Its only emiting finished() after i started the application but not after quiting it!
    If it does emit the signal then QProcess works OK. Maybe the application you start spawns another application and quits immediately?

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.