Results 1 to 13 of 13

Thread: problem in QProcess

  1. #1
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question problem in QProcess

    hi friends,
    please help
    i create a code to embed gtk window to my Qt app ..
    mainwindow.cpp
    Qt Code:
    1. procc2 = new QProcess();
    2. procc2->setProcessChannelMode(QProcess::MergedChannels);
    3. connect(procc2, SIGNAL(readyReadStandardOutput()), this, SLOT(readFromStdout2()));
    To copy to clipboard, switch view to plain text mode 

    this is a timer function calling every 400 milli sec
    Qt Code:
    1. MainWindow::timeout{
    2. if(...)
    3. {
    4. QString program4 = "./gtk_demo2";
    5. QStringList arguments2;
    6. if(procc2->state() != QProcess::Running)
    7. {
    8. procc2->start(program4, arguments2);
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

    readfromstdout() function will call the function to embed the process
    Qt Code:
    1. MainWindow::readFromStdout2()
    2. {
    3. int j = 0;
    4. bool ok;
    5. QString out;
    6. printf("in singal fin\n");
    7. out = procc2->readAllStandardOutput();
    8. j = out.toInt(&ok, 16);
    9. printf("j =%d\n",j);
    10. if(j == 1)
    11. printf("device not connected\n");
    12. else{
    13. printf("the device connected\n");
    14. embed();
    15. }
    16.  
    17. }
    To copy to clipboard, switch view to plain text mode 

    this is my code and the function embed() will embed the "gtk_demo" window if it returns 0 or anything ...
    the problem is on first time if i spawn the signal "readyReadStandardOutput()"
    is not emitted and readFromStdout2() slot is not called .
    i closed the spawned gtk application "gtk_demo" and as i put the procc in loop again it spawn "gtk_demo" its emitting "readyReadStandardOutput()" and embedding perfectly ... why??
    i changed gtk application to a Qt application and try the same thing its worked in the first attempt ...

    please help me ...

  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: problem in QProcess

    Did you check the value of "ok" variable?

  3. The following user says thank you to wysota for this useful post:

    wagmare (3rd January 2009)

  4. #3
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem in QProcess

    no but even "in singal fin\n" is not printing ... its not entering the slot readFromStdout2()
    .. only after closing the gtk window then only i get the output ....

  5. #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: problem in QProcess

    Maybe the other process doesn't write anything on its standard output? Or it doesn't flush the descriptor...

  6. #5
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem in QProcess

    thanks for reply .. but i use merged channels and i am getting standard output but only after the process ie.. the gtk window closed ..

  7. #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: problem in QProcess

    That's why I'm saying the other process is not flushing its stdout descriptor. Your data gets stuck in a pipe buffer between the two processes. If you are the author of "the other app", simply write a newline after the data or call (f)flush() on stdout.

  8. The following user says thank you to wysota for this useful post:

    wagmare (5th January 2009)

  9. #7
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem in QProcess

    Quote Originally Posted by wysota View Post
    That's why I'm saying the other process is not flushing its stdout descriptor. Your data gets stuck in a pipe buffer between the two processes. If you are the author of "the other app", simply write a after the data or call (f)flush() on stdout.
    thanks for reply ..
    i try the both ((f)flush() ,newline )but still its giving the same ... when the process gets finished and closed only its giving the stdout.
    i cant get any thing .........

  10. #8
    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: problem in QProcess

    What if you run that application separately from the terminal? Do you see its output immediately?

  11. #9
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem in QProcess

    yes its running quickly ... after i execute gtk_demo separately it shows the output before showing the window ... its quick ..

  12. #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: problem in QProcess

    Could we see some more code of yours?

  13. #11
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem in QProcess

    my code or that Gtk code ..?

    my Qt code:
    Qt Code:
    1. timer2 = new QTimer(this);
    2. timer2->setSingleShot(TRUE);
    3.  
    4. timer_FS = new QTimer(this);
    5. timer_FS->start(300);
    6.  
    7. container2 = new QX11EmbedContainer(this);
    8. container2->setPalette(QPalette(Qt::red));
    9. container2->setAutoFillBackground(true);
    10.  
    11.  
    12. procc2 = new QProcess();
    13. procc2->setProcessChannelMode(QProcess::MergedChannels);
    14. connect(procc2, SIGNAL(readyReadStandardOutput()), this, SLOT(readFromStdout2()));
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. QHBoxLayout *layoout4 = new QHBoxLayout();
    2. layoout4->addWidget(container2);
    3.  
    4. mainFrame5->setLayout(layoout4);
    5.  
    6. connect(timer2, SIGNAL(timeout()), this, SLOT(embed2()));
    7. connect(FPSBackButton, SIGNAL(clicked()), this, SLOT(timeout_bg2()));
    8. connect(timer_FS, SIGNAL(timeout()), this, SLOT(timeout_FS()));
    To copy to clipboard, switch view to plain text mode 

    /*setFPScanner =1 will be set when a embed Button is clicked in my Qt app*/
    Qt Code:
    1. void
    2. MainWindow::timeout_FS(){
    3.  
    4. if(setFPScanner == 1)
    5. mainstackedWidget->setCurrentIndex(4);
    6. else if(embedFPScanner == 1)
    7. {
    8. QString program4 = "./gtk_demo2";
    9. //QString program4 = "./animate";
    10. QStringList arguments2;
    11. if(procc2->state() != QProcess::Running)
    12. {
    13. procc2->start(program4, arguments2);
    14. }
    15. }
    16.  
    17. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void MainWindow::readFromStdout2()
    2. {
    3. int j = 4;
    4. bool ok;
    5. QString out;
    6. out = procc2->readAllStandardOutput();
    7. j = out.toInt(&ok, 16);
    8. printf("j =%d\n",j);
    9. if(j == 1)
    10. printf("device not connected\n");
    11. else{
    12. printf("the device connected\n");
    13. timer2->start(2000);
    14. }
    15.  
    16. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void MainWindow::embed2()
    2. {
    3.  
    4. container2->embedClient(widedit->text().toInt(&ok, 16));
    5. }
    To copy to clipboard, switch view to plain text mode 

    /*this will be set setFpscanner when a back button in my Qt app is clicked*/
    Qt Code:
    1. void MainWindow::timeout_bg2()
    2. {
    3. timer_FS->stop();
    4. setFPScanner = 0;
    5. mainstackedWidget->setCurrentIndex(1);
    6. timer_FS->start();
    7. }
    To copy to clipboard, switch view to plain text mode 

    this is my whole code in that part i written .... if u find any error please help me ...

  14. #12
    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: problem in QProcess

    And how do you output the data from the slave app?

  15. #13
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem in QProcess

    Quote Originally Posted by wysota View Post
    And how do you output the data from the slave app?
    the gtk window will print 1 using printf if the device is not connected else it print 0 .. externly running
    gtk_demo.c
    Qt Code:
    1. if(retval != FTR_RETCODE_OK){
    2. if(retryCountLevel1 <= MAX_RETRY_COUNT){
    3. FreeResource();
    4. usleep(MAX_RETRY_SLEEP);
    5. retryCountLevel1++;
    6. goto retry_level1;
    7. }else{
    8. dump_line(stdin);
    9. printf("1");
    10. FreeResource();
    11. return -1;
    12. }
    13. }
    14. printf("0\n");
    To copy to clipboard, switch view to plain text mode 
    this is the gtk code ..
    so i use
    my Qt app
    readyReadStandardOutput() for the process and i try to get that as
    Qt Code:
    1. int j = 4;
    2. bool ok;
    3. const char *str;
    4. QString out;
    5. out = procc2->readAllStandardOutput();
    6. ba = out.toLatin1();
    7. str = ba.data();
    8. //j = out.toInt(&ok, 16);
    9. printf("the string on returning:%s\n",str);
    10. if(strcmp(str,"1") == 0){
    11. printf("device not connected\n");
    12. }
    13. else{
    14. printf("the device connected\n");
    15. timer2->start(2000);
    16. }
    17.  
    18. }
    To copy to clipboard, switch view to plain text mode 

    did u find any thing i done foolishly ...
    if so please help ..

Similar Threads

  1. QProcess problem
    By Mystical Groovy in forum Qt Programming
    Replies: 2
    Last Post: 2nd December 2008, 20:07
  2. QProcess and kfmclient exec problem
    By ramazangirgin in forum Qt Programming
    Replies: 5
    Last Post: 6th June 2008, 08:31
  3. QThread and QProcess problem
    By codebehind in forum Qt Programming
    Replies: 13
    Last Post: 7th August 2007, 08:11
  4. Quoting problem with QProcess
    By the_bis in forum Qt Programming
    Replies: 1
    Last Post: 15th December 2006, 11:24
  5. problem with qprocess
    By deekayt in forum Qt Programming
    Replies: 2
    Last Post: 13th June 2006, 13:30

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.