Results 1 to 13 of 13

Thread: Qprocess never end in MS windows

Hybrid View

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

    Default Re: Qprocess never end in MS windows

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

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

    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

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

    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?

  4. #4
    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.

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

    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,

  6. #6
    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.

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

    Default Re: Qprocess never end in MS windows

    Do those slots get called at all?

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

    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é

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

    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é

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

    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
  •  
Qt is a trademark of The Qt Company.