Results 1 to 6 of 6

Thread: No Interactive feel-QProcess

  1. #1
    Join Date
    Jan 2008
    Posts
    4
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default No Interactive feel-QProcess

    Hi guys....
    Im usin Qt 3.3.8 for designing a GUI based editor for C/C++ programs.
    I use QProcess for running the program
    For reading output I use readLineStdout().It all works fine .But im not able to get the feel of Interaction---the program simply goes on getting input and then finally it prints the otput.....I'll explain u my situation...

    This is what I expect when I run a program:
    Program:Enter the number of strings
    myself: 2
    Prog:Enter the string 1
    my:aaa
    Prog:Echoed string:aaa
    Prog:Enter the string 2
    my:bbb
    Prog:Echoed string:bbb
    but this is what happens when I run the program:
    Prog: [ Nothin appears(at this instant) in the Text edit thats designd for showing the output ]
    my:2
    my:aaa
    my:bbb
    Prog:Enter the string 1
    Echoed string:aaa
    Enter the string 2
    Echoed string:bbb [all of these appear at a single instance]
    Now this is vat is my problem....
    Great ones shall HELP me
    PLZZZZZZZZZZZZZZZZZZZ
    Last edited by jpn; 9th January 2008 at 21:02. Reason: missing [quote] tags

  2. #2
    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: No Interactive feel-QProcess

    The interaction has to be provided by you. You have to read the data from the process, then allow user to do something and then write some data back to the process, etc. You should use signals and slots to obtain information about new data available to read and then do the reading. Instead you are probably reading everything in one go somewhere in your app. If not, please provide some code as now this is just guessing what you did.

  3. #3
    Join Date
    Jan 2008
    Posts
    4
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: No Interactive feel-QProcess

    I' ve handled signals and slots and all but still there is the problem...
    well here is the code..
    Qt Code:
    1. proc = new QProcess( this );
    2. proc->setCommunication( QProcess::Stdin |QProcess::Stdout|QProcess::Stderr|QProcess:big grin upStderr );
    3. proc->addArgument( "./a.out" );
    4. connect( proc, SIGNAL(readyReadStdout()),this, SLOT(readFromStdout()) );
    5.  
    6. if ( !proc->start() ) {
    7. }
    8. if(proc->isRunning()) {
    9. proc->writeToStdin(InputLineEdit->displayText());
    10. }
    11.  
    12. void MainForm::readFromStdout()
    13. {
    14. while(proc->canReadLineStdout()) {
    15. OutputEdit->append( proc->readLineStdout() +'\n');
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    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: No Interactive feel-QProcess

    What about reacting to the output received and feeding user's response back to the process? I don't see it in your code.

  5. #5
    Join Date
    Jan 2008
    Posts
    4
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: No Interactive feel-QProcess

    why it is there in the readFromStdout()...[here i get the process' o/p and put it in a TextEdit] and also the InputLineEdit->displayText()..[here i get the i/p from the lineedit and give it to the writeToStdin()]

    Qt Code:
    1. 1.
    2. proc = new QProcess( this );
    3. 2.
    4. proc->setCommunication( QProcess::Stdin |QProcess::Stdout|QProcess::Stderr|QProcess:big grin upStderr );
    5. 3.
    6. proc->addArgument( "./a.out" );
    7. 4.
    8. connect( proc, SIGNAL(readyReadStdout()),this, SLOT([B][U]readFromStdout()[/U][/B]) );
    9. 5.
    10.  
    11. 6.
    12. if ( !proc->start() ) {
    13. 7.
    14. }
    15. 8.
    16. if(proc->isRunning()) {
    17. 9.
    18. proc->[B][U]writeToStdin(InputLineEdit->displayText());[/U][/B]
    19. 10.
    20. }
    21. 11.
    22.  
    23. 12.
    24. void MainForm::readFromStdout()
    25. 13.
    26. {
    27. 14.
    28. while(proc->canReadLineStdout()) {
    29. 15.
    30. [B][U] OutputEdit->append( proc->readLineStdout() +'\n');[/U][/B]
    31. 16.
    32. }
    33. 17.
    34. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    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: No Interactive feel-QProcess

    In readFromStdOut() you only read and present the data back to the user, not write anything back... If the flow is not what you expect then that's because you are not controlling it enough. You should only allow your user to enter data if the backend process tells you so. Otherwise you'll always have the same problem, because if you input data, it gets queued in a buffer and then the application reads from the buffer, not knowing if the data got there before or after sending a prompt. You'd have to clear the buffer after sending the prompt to be certain of that.

    So bottom line, you need a slot that will send the data to the process after receiving some data from the process. Because currently you only write something when you start the process (at least that's what the code you have shown does).

Similar Threads

  1. QProcess and Pipes
    By KaptainKarl in forum Qt Programming
    Replies: 1
    Last Post: 9th April 2007, 23:11
  2. QProcess / system call not working under linux. Why?
    By johnny_sparx in forum Qt Programming
    Replies: 12
    Last Post: 11th March 2006, 00:32

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.