Results 1 to 12 of 12

Thread: [SOLVED] QProcess Java Application Not Working

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanked 342 Times in 324 Posts

    Default Re: QProcess Java Application Not Working

    QProcess will start your command asynchronously, you'll have to wait before checking if its running or any error occured. From Qt docs:
    Processes are started asynchronously, which means the started() and error() signals may be delayed. Call waitForStarted() to make sure the process has started (or has failed to start) and those signals have been emitted.

  2. #2
    Join Date
    Jun 2013
    Posts
    46
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows
    Thanks
    24

    Default Re: QProcess Java Application Not Working

    Tried multiple methods but to no avail

    Are there any #includes I should add to my .cpp file to call function
    My function just initializes the the QProcess as above and tries to run it

    Do I need to create a Java virtual machine before I try calling QProcess

    Is there any simple tutorial I can follow?

    Kind Regards

  3. #3
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanked 342 Times in 324 Posts

    Default Re: QProcess Java Application Not Working

    My function just initializes the the QProcess as above and tries to run it
    And it does not wait for it to start and does not check for error values.
    Qt Code:
    1. {
    2. // ...
    3. QProcess *myProcess = new QProcess(this);
    4. connect(myProcess, SIGNAL(error(QProcess::ProcessError)), this, SLOT(checkError(QProcess::ProcessError)));
    5. connect(myProcess, SIGNAL(started()), this, SLOT(processStarted()));
    6. connect(myProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(processExited(int,QProcess::ExitStatus)));
    7. myProcess->start(program, arg);
    8. // .. here you exit the current function and wait for process to start / fail to start
    9. }
    10.  
    11. void MyClass::processStarted(){
    12. qDebug() << "Hurray ! MyProcess started!";
    13. }
    14.  
    15. void MyClass::checkError(QProcess::ProcessError err){
    16. qDebug() << "Process error: " << err;
    17. }
    18.  
    19. void MyClass::processExited(int exitCode, QProcessExitStatus status){
    20. qDebug() << "Process exited with code: " <<exitCode << ", status: " << status;
    21. }
    To copy to clipboard, switch view to plain text mode 

    Alternative is to call waitForFinished() after start(), but this can freeze the gui.
    It is important to understand the asynchronous nature of QProcess, this:
    Qt Code:
    1. QProcess *myProcess = new QProcess(this);
    2. myProcess->start(program, arg);
    3.  
    4. qDebug() << myProcess->state(); //Ref 1
    5. qDebug() << myProcess->error(); //Ref 2
    To copy to clipboard, switch view to plain text mode 
    will not work correctly in most of the cases, because you check the status and error value of QProcess before it is initialized and started.

Similar Threads

  1. QProcess not working correctly
    By m_bishop in forum Qt Programming
    Replies: 2
    Last Post: 28th May 2013, 16:36
  2. Replies: 3
    Last Post: 28th October 2011, 23:24
  3. Qt+QWebKit+Java+Flash not working
    By progDes in forum Qt Programming
    Replies: 2
    Last Post: 30th April 2009, 16:49
  4. Qprocess not working
    By bruccutler in forum Newbie
    Replies: 3
    Last Post: 15th February 2007, 04:48
  5. QProcess not working in some cases
    By munna in forum Qt Programming
    Replies: 1
    Last Post: 1st August 2006, 09:58

Tags for this Thread

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.