Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. What SIGNAL to monitor for incorrect QProocess ?
Forum Updated to NodeBB v4.3 + New Features

What SIGNAL to monitor for incorrect QProocess ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 175 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by Anonymous_Banned275
    #1

    I am passing char * to QProcess.
    As far as I can tell; QProcess has no option for passing char*, but the QProcess starts and finishes ... but does not deliver expected results.

    Which one of QProcess standard SIGNALs should I monitor for possible error?

     void errorOccurred(QProcess::ProcessError error)
     void finished(int exitCode, QProcess::ExitStatus exitStatus = NormalExit)
     void readyReadStandardError()
     void readyReadStandardOutput()
     void started()
     void stateChanged(QProcess::ProcessState newState)
    

    And per my other post - how do I make the passed (error) data humanly readable - since I do no define them.

    PS
    If I do pass QSTring to QPProcess - what is the corrent systex for passinf "system" function ?
    I did try splitting to "system" and then arguments - but it does not work with the "system" (function) that way .

    YES, I can go back to passing data to "bash"...
    BUT bash script does not accept some standard options likes "|" and "tee".

              const char *command = "hcitool -i hci0 scan --flush | tee /tmp/temp";
                //command = "hcitool -i hci0 scan --flush  | tee /tmp/temp ";
                //command = "hcitool | tee /tmp/temp ";
                //ystem(command);
                // or even just
                //system("rfkill list > textEdit");
                // exit(66);
    
    
    
                //QString s = "hcitool -i hci0 scan --flush | tee /tmp/temp"
                process ->start(command); // system("hcitool -i hci0 scan --flush >>/tmp/temp  "));
                process->state();
    
    
    JonBJ 1 Reply Last reply
    0
    • A Anonymous_Banned275

      I am passing char * to QProcess.
      As far as I can tell; QProcess has no option for passing char*, but the QProcess starts and finishes ... but does not deliver expected results.

      Which one of QProcess standard SIGNALs should I monitor for possible error?

       void errorOccurred(QProcess::ProcessError error)
       void finished(int exitCode, QProcess::ExitStatus exitStatus = NormalExit)
       void readyReadStandardError()
       void readyReadStandardOutput()
       void started()
       void stateChanged(QProcess::ProcessState newState)
      

      And per my other post - how do I make the passed (error) data humanly readable - since I do no define them.

      PS
      If I do pass QSTring to QPProcess - what is the corrent systex for passinf "system" function ?
      I did try splitting to "system" and then arguments - but it does not work with the "system" (function) that way .

      YES, I can go back to passing data to "bash"...
      BUT bash script does not accept some standard options likes "|" and "tee".

                const char *command = "hcitool -i hci0 scan --flush | tee /tmp/temp";
                  //command = "hcitool -i hci0 scan --flush  | tee /tmp/temp ";
                  //command = "hcitool | tee /tmp/temp ";
                  //ystem(command);
                  // or even just
                  //system("rfkill list > textEdit");
                  // exit(66);
      
      
      
                  //QString s = "hcitool -i hci0 scan --flush | tee /tmp/temp"
                  process ->start(command); // system("hcitool -i hci0 scan --flush >>/tmp/temp  "));
                  process->state();
      
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @AnneRanch
      You have asked this so many times, and been answered. You cannot execute hcitool -i hci0 scan --flush | tee /tmp/temp as the command in process ->start(command). The answer is always the same:

      process ->start("/bin/sh", QStringList() << "-c" << command);
      

      YES, I can go back to passing data to "bash"...

      BUT bash script does not accept some standard options likes "|" and "tee".

      Completely incorrect. It is only either /bin/sh or /bin/bash which does accept and interpret |. tee has nothing to do with the shell, and works fine from either.

      If I do pass QSTring to QPProcess - what is the corrent systex for passinf "system" function ?

      There is no system-anything to pass to QProcess. system() is an alternative to using QProcess. You are better using QProcess in Qt programs and not system(). There is nothing system() does that QProcess() cannot do, but there are things you can do with QProcess which cannot be done with system(). You could save yourself time but not trying to use system(), I have shown you the equivalent process ->start() to use instead.

      Which one of QProcess standard SIGNALs should I monitor for possible error?

      void errorOccurred(QProcess::ProcessError error)

      errorOccurred() is the signal for errors launching QProcess. You will doubtless be interested in other things which happen that are not process errors, even if you might think they should be. They may be reported by reading stderr (readyReadStandardError()) and possibly stdout too.

      For the simplest case just use

      const char *command = "hcitool -i hci0 scan --flush | tee /tmp/temp";
      process ->start("/bin/sh", QStringList() << "-c" << command);
      process->waitForFinished();
      qDebug() << process->readAllStandardError();
      qDebug() << process->readAllStandardOutput();
      

      You should also connect on the errorOccurred signal, just in case.

      1 Reply Last reply
      3

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved