Results 1 to 13 of 13

Thread: Qprocess never end in MS windows

  1. #1
    Join Date
    Feb 2006
    Location
    Portugal
    Posts
    24
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Qprocess never end in MS windows

    Hi,
    I'm trying to run some external programs fron a qt4.0 interface and catch the standardoutput and standard error.

    I'm using Qprocesses class. Things work very good im Linux (Opensuse 10.0) but in windows (2000 Pro, qt4.1 open version) the external process never end and the finished sign is not emmitted.

    my code is very easy, is a small fraction

    QProcess nh3d;
    Ui_MainWindow ui;
    void batchprocess::nhdstart()
    {

    if(nh3d.state() ==0 )
    nh3d.start("c:\\winnt\\system32\\mem");
    else
    {
    qWarning("Program it's already running \n");
    ui.textBrowser_2->append("Program it's already running \n");
    ui.textBrowser->append(nh3d.readAllStandardOutput());
    }
    }

    the function batchprocess::nhdstart() is connected to a click of a pushup button and it is working.

    Any help or clues will be very appreciated.
    I've found an old thread on the subject but the solutions there aren't good for me


    best Regards

  2. #2
    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 never end in MS windows

    What does nh3d.start(...) return?

  3. #3
    Join Date
    Feb 2006
    Location
    Portugal
    Posts
    24
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qprocess never end in MS windows

    Quote Originally Posted by jacek
    What does nh3d.start(...) return?
    I really don't know but the
    SIGNAL(started( ))
    is emmited because it is linked to a label that displays running after theexternal program start, and that is working fine, even in windows.

    Subsequent clicks in the button will write in a textframe
    "program is already running"
    so
    nh3d.state() is different from 0

    the program necer ends.
    if I choose a external program with a huge amount of output almost all the output is displayes in a textframe but the last three or four lines

  4. #4
    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 never end in MS windows

    How do you read that output? Maybe it stops becuse of full buffers?

  5. #5
    Join Date
    Feb 2006
    Location
    Portugal
    Posts
    24
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qprocess never end in MS windows

    Quote Originally Posted by jacek
    How do you read that output? Maybe it stops becuse of full buffers?
    I read it by doing!
    ui.textBrowser->append(nh3d.readAllStandardOutput());

    and the program do not stop! It never ends

  6. #6
    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 never end in MS windows

    Quote Originally Posted by antonio.r.tome
    I read it by doing!
    ui.textBrowser->append(nh3d.readAllStandardOutput());
    Each time the readyReadStandard...() signal is emitted?

  7. #7
    Join Date
    Feb 2006
    Location
    Österreich
    Posts
    35
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Qprocess never end in MS windows

    Yes, you're reading all the standard output, but only one time. You need to connect the signal readyReadStandardOutput to a slot for using readAllStandardOutput.

    Say the process you are running sends
    "Blah blah blah blah blah
    Blah blah blah blah blah
    Blah blah blah blah blah
    Blah blah blah blah blah
    Blah blah blah blah blah"

    to stdout. Your call to nh3d.readAllStandardOutput() picks it up, which is fine. But now say the process wants to say

    "Blah blah blah blah blah" again and you are not checking to see if anything is there.

    If you don't want to do signals and slots, and you don't need interactive use of the program until the other process finishes, you can use a blocking wait:

    Qt Code:
    1. if (nh3d.state() ==0 )
    2. nh3d.start("c:\\winnt\\system32\\mem");
    3. else while (nh3d.state() == QProcess::Running)
    4. {
    5. if (nh3d.waitForReadyRead(MAXIMUM TIME IN MILLISECONDS YOU ARE WILLING TO WAIT FOR THE PROCESS TO SEND SOMETHING TO THE STREAM) == TRUE) dosomethingwiththedata;
    6. else
    7. decidewhattodoiftheprocessisn'tsendingyouanythingafteralongtime,likekillingitandexiting;
    8. }
    To copy to clipboard, switch view to plain text mode 
    Just make sure the while loop does not run forever . In this pseudocode, it probably would unless the program normally exits on its own.
    My philosophy is: If you can use a free, open-source alternative: do it. And if you can't, pretend it's free and open-source and hope you don't get caught.

  8. #8
    Join Date
    Feb 2006
    Location
    Portugal
    Posts
    24
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qprocess never end in MS windows

    [QUOTE=michel]Yes, you're reading all the standard output, but only one time. You need to connect the signal readyReadStandardOutput to a slot for using readAllStandardOutput.

    I'm sorry I didn't sent you all the code!
    I'm already reading the standard Output in a slot of a function connected to readyReadStandardOutput signal!

    and as I said it works great in Linux.

    I have the follwoing code aditional code.


    .....
    QObject::connect(&nh3d, SIGNAL(readyReadStandardOutput ()), &readwrite, SLOT(owrite()));
    QObject::connect(&nh3d, SIGNAL(readyReadStandardError ()), &readwrite, SLOT(ewrite()));


    readwrite is a class with the slots owrite e ewrite
    .............................
    void Readoutput:write()
    {
    ui.textBrowser->append(nh3d.readAllStandardOutput());
    /
    }
    void Readoutput::ewrite()
    {
    ui.textBrowser_2->append(nh3d.readAllStandardError());





    ......................

    Because this weird problem today I'm going to Update my windiows 2000 to XP to see if the problem solves by itself.

    Best regards,

  9. #9
    Join Date
    Feb 2006
    Location
    Österreich
    Posts
    35
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Qprocess never end in MS windows

    Hm. Weird. Maybe processes in Windows just don't behave correctly (that would sure be a surprise).
    My philosophy is: If you can use a free, open-source alternative: do it. And if you can't, pretend it's free and open-source and hope you don't get caught.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qprocess never end in MS windows

    Do those slots get called at all?

  11. #11
    Join Date
    Feb 2006
    Location
    Portugal
    Posts
    24
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qprocess never end in MS windows

    Quote Originally Posted by wysota
    Do those slots get called at all?
    Yes

    if i put a command with large output. (I use nh3d an executable program of my one, where the standards erro and output are flushed every time they are used) I obtain the full output in stderr and the output of stdout behaves great but for the last two or three lines. It happens as the external processed freezed just before finished.

    The example I put were I call mem was only to see if with a native windows application I got some output, but the behavior is the same.

    I've just update for XP but the results are the same.

    António Tomé

  12. #12
    Join Date
    Feb 2006
    Location
    Portugal
    Posts
    24
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qprocess never end in MS windows

    I've solved de problem:

    In my example
    QProcess nh3d

    is definided as a global variable (C++ books are always alerting to avoid them ...)

    Kwow I've defined
    QProcess nh3d as a plublic variable of the class which contais the slot that starts the Qprocess and everthing works fine in linux and windows.

    The remaining, and maybe unuseful, question is to know what are the right question:

    Why it didn't work as was in windows? Or
    why it work as it was in linux?

    my best Regards and many thanks to everyone o tried to help

    António Tomé

  13. #13
    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 never end in MS windows

    Quote Originally Posted by antonio.r.tome
    Why it didn't work as was in windows? Or
    why it work as it was in linux?
    One possible explanation is that it was instantiated before QCoreApplication, which performes some platform-dependent initialization.

Similar Threads

  1. Replies: 4
    Last Post: 4th June 2007, 08:33
  2. QProcess extremely slow on Windows?
    By Pepe in forum Qt Programming
    Replies: 2
    Last Post: 26th March 2007, 00:25
  3. need help for QProcess under windows
    By patcito in forum Qt Programming
    Replies: 4
    Last Post: 26th May 2006, 19:54
  4. QProcess +standard error + windows
    By antonio.r.tome in forum Qt Programming
    Replies: 0
    Last Post: 18th April 2006, 14:58
  5. QProcess problem with windows batch file
    By bood in forum Qt Programming
    Replies: 11
    Last Post: 6th January 2006, 08:08

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.