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