Results 1 to 8 of 8

Thread: Deleting QProcess

  1. #1
    Join Date
    Jan 2007
    Posts
    92
    Thanks
    14
    Thanked 1 Time in 1 Post

    Default Deleting QProcess

    I have problem when I am deleting QProcesses and I dont get any output. If I comment out deleteLater() method to delete processes I get right output in the form of string as expected. I have tried to use delete and deleteLater to delete processes. But something is still going wrong. I have created two seperate process to read data from external scripts. I am using QT3.
    Qt Code:
    1. //Declared member Functions globally.
    2. QString strFirstProcess;
    3. QString strSecondProcess;
    4. QProcess process1;
    5. QProcess process2;
    6.  
    7. QString CMainTemplate::CreateControls()
    8.  
    9. {
    10. lineEdit->setText(GetFirstProcess());
    11. lineEdit2->setText(GetSecondProcess());
    12. }
    13.  
    14. //...FIRST PROCESS
    15. QString CMainTemplate::GetFirstProcess()
    16.  
    17. {
    18.  
    19. process= new QProcess(this);
    20.  
    21. //Add the arguments
    22. process1->addArgument( "/bash" );
    23. process->addArgument("GetFirstScript");
    24.  
    25.  
    26. if ( !process->start() )
    27. {
    28. qDebug("ERROR: First Process Never Started");
    29. process->deleteLater();
    30. }
    31.  
    32. connect(process, SIGNAL(readyReadStdout()), this, SLOT(readFirstProcess()));
    33.  
    34. return strFirstProcess;
    35.  
    36. }
    37. //...SECOND PROCESS
    38. QString CMainTemplate::GetSecondProcess()
    39.  
    40. {
    41.  
    42. process1= new QProcess(this);
    43.  
    44. //Add the arguments
    45. process1->addArgument( "/bash" );
    46. process1->addArgument("GetSecondScript");
    47.  
    48.  
    49. if ( !process1->start() )
    50. {
    51. qDebug("ERROR: Second Process Never Started");
    52. process1->deleteLater();
    53. }
    54.  
    55. connect(process1, SIGNAL(readyReadStdout()), this, SLOT(readSecondProcess()));
    56.  
    57. return strSecondProcess;
    58.  
    59. }
    60. //=====================SLOTS TO READ STD OUT ===================================================
    61.  
    62. void CMainTemplate::readFirstProcess()
    63. {
    64. QString str = process->readStdout() ;
    65. strFirstProcess = str;
    66. process->deleteLater();
    67. }
    68. void CMainTemplate::readSecondProcess()
    69.  
    70. {
    71. QString str = process1->readStdout() ;
    72. strSecondProcess = str;
    73. process1->deleteLater();
    74. }
    To copy to clipboard, switch view to plain text mode 

  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: Deleting QProcess

    You probably kill the process before all output is generated. The signal you connect to is emited when there is any data to read (like 1 character) and not when all data is pending. I suggest you delete the process object only when it tells you the process it controls has ended.

  3. #3
    Join Date
    Jan 2007
    Posts
    92
    Thanks
    14
    Thanked 1 Time in 1 Post

    Default Re: Deleting QProcess

    how do i know that particular process has ended its loop or should I delete only once after returning the string I mean data.

  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: Deleting QProcess

    Look at the signals QProcess offers.

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

    user_mail07 (26th January 2008)

  6. #5
    Join Date
    Jan 2007
    Posts
    92
    Thanks
    14
    Thanked 1 Time in 1 Post

    Default Re: Deleting QProcess

    Well my application still crash and I get segmentation fault always. I tried processExited and launchedfinished signals too. It is just the matter of deleting qprocessed when I am running sequentially.

    I tried few things such as

    connect( process, SIGNAL(processExited()),this, SLOT(deleteLater()) );
    OR
    connect( process, SIGNAL(processExited()),this, SLOT(stopProces()) );

    Qt Code:
    1. QString CMainTemplate::GetFirstProcess()
    2. {
    3.  
    4. process= new QProcess(this);
    5.  
    6. //Add the arguments
    7.  
    8. process->addArgument( "/bash" );
    9.  
    10. process->addArgument("GetFirstScript");
    11. if ( !process->start() )
    12. {
    13.  
    14. qDebug("ERROR: First Process Never Started");
    15.  
    16. process->deleteLater();
    17. }
    18.  
    19.  
    20. connect(process, SIGNAL(readyReadStdout()), this, SLOT(readFirstProcess()));
    21.  
    22. return strFirstProcess;
    23.  
    24.  
    25.  
    26. }
    27.  
    28.  
    29. QString CMainTemplate::stopProces()
    30. {
    31. const QObject *sen=sender();
    32. delete sen;
    33. }
    To copy to clipboard, switch view to plain text mode 

  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: Deleting QProcess

    Have you tried debugging to see where and why it crashes?

  8. #7
    Join Date
    Jan 2007
    Posts
    92
    Thanks
    14
    Thanked 1 Time in 1 Post

    Default Re: Deleting QProcess

    I tried to put some debug statements to see where it exactly crash. The segmentaion fault does not provide me any information. As soon as I call CreateContorls( ) to call two sequential process my application crash. It never prints any thing else . It looks like Slots readFirstProcess and readSecondProcess never get called otherwise it should print debug statements from slots such as "Print ReadOut Process1".

    The output I receive after calling CreateControls() method is :-

    Print Statement 1
    Print Statement 2
    Print Statement 3
    Print Statement 4
    Print Statement 5
    Print Statement 6

    But if executes only one process with GetFirstProcess( ) while commenting out second GetSecondProcess() then there is no problem.
    Qt Code:
    1. QString CMainTemplate::CreateControls()
    2. {
    3.  
    4. lineEdit->setText(GetFirstProcess());
    5. //lineEdit2->setText(GetSecondProcess());
    6. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. QString CMainTemplate::CreateControls()
    2. {
    3.  
    4. lineEdit->setText(GetFirstProcess());
    5. lineEdit2->setText(GetSecondProcess());
    6. }
    7.  
    8. QString CMainTemplate::GetFirstProcess()
    9. {
    10. process= new QProcess(this);
    11. //Add the arguments
    12. process1->addArgument( "/bash" );
    13. process->addArgument("GetFirstScript");
    14.  
    15. qDebug("Print Statement 1");
    16. connect(process, SIGNAL(readyReadStdout()), this, SLOT(readFirstProcess()));
    17.  
    18. qDebug("Print Statement 2");
    19. if ( !process->start() )
    20. {
    21. qDebug("ERROR: First Process Never Started");
    22. process->deleteLater();
    23. }
    24.  
    25. qDebug("Print Statement 3");
    26.  
    27. return strFirstProcess;
    28. }
    29.  
    30. //...SECOND PROCESS
    31.  
    32. QString CMainTemplate::GetSecondProcess()
    33. {
    34. process1= new QProcess(this);
    35. //Add the arguments
    36. process1->addArgument( "/bash" );
    37. process1->addArgument("GetSecondScript");
    38.  
    39. qDebug("Print Statement 4");
    40.  
    41. connect(process1, SIGNAL(readyReadStdout()), this, SLOT(readSecondProcess()));
    42.  
    43. qDebug("Print Statement 5");
    44.  
    45. if ( !process1->start() )
    46. {
    47. qDebug("ERROR: Second Process Never Started");
    48. process->deleteLater();
    49. }
    50.  
    51. qDebug("Print Statement 6");
    52.  
    53. return strSecondProcess;
    54. }
    55.  
    56. //=====================SLOTS TO READ STD OUT ===================================================
    57.  
    58. void CMainTemplate::readFirstProcess()
    59. {
    60.  
    61. QString str = process->readStdout() ;
    62. strFirstProcess = str;
    63. qDebug("Print ReadOut Process1);
    64. process->deleteLater();
    65.  
    66. }
    67.  
    68. void CMainTemplate::readSecondProcess()
    69. {
    70. QString str = process1->readStdout() ;
    71. strSecondProcess = str;
    72. qDebug("Print ReadOut Process2);
    73. process1->deleteLater();
    74.  
    75. }
    To copy to clipboard, switch view to plain text mode 

  9. #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: Deleting QProcess

    Quote Originally Posted by user_mail07 View Post
    I tried to put some debug statements to see where it exactly crash.
    I meant using a debugger and its stack tracing abilities.

Similar Threads

  1. QProcess and Pipes
    By KaptainKarl in forum Qt Programming
    Replies: 1
    Last Post: 9th April 2007, 23:11
  2. QProcess extremely slow on Windows?
    By Pepe in forum Qt Programming
    Replies: 2
    Last Post: 26th March 2007, 00:25
  3. Replies: 1
    Last Post: 6th March 2007, 15:27
  4. problem with qprocess
    By deekayt in forum Qt Programming
    Replies: 2
    Last Post: 13th June 2006, 13:30
  5. Replies: 4
    Last Post: 13th February 2006, 11:35

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.