Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. QtonPi
  4. QProcess doesn´t emit finished() when done

QProcess doesn´t emit finished() when done

Scheduled Pinned Locked Moved Unsolved QtonPi
24 Posts 5 Posters 19.3k Views 2 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #4

    Hi,

    Did you check the output of the QProcess::error method ?

    You should also check the standard error and output content. That should give you more clues about what is happening.

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • L Offline
      L Offline
      LogiSch17
      wrote on last edited by LogiSch17
      #5

      Hi,
      i got

      QObject::connect(copy, SIGNAL(errorOccurred(QProcess::ProcessError)), this, SLOT(errorFound(QProcess::ProcessError)));
      

      copy is my Qprocess.
      which was also never emmited. Is there any more error methods i could read?

      This is how my code looks like.

      header:

      #ifndef UPDATE_HANDLER_H
      #define UPDATE_HANDLER_H
      
      #include <QtCore/QObject>
      #include <QProcess>
      #include <QFile>
      #include <QStringList>
      #include <QProcess>
      
      class UpdateHandler : public QObject
      {
          Q_OBJECT
      
          public:
              UpdateHandler(QObject* parent = nullptr);
      
      
          signals:
              void updateSuccess();
              void updateFailed();
      
          private slots:
              void fileSearch();
              void fileCopied(int);
      
          private:
              QFile* file;
              QFile* updEnc;
              QStringList cpscript;
              QProcess* copy;
              QString filename;
              QFile log;
      
      };
      
      #endif // UPDATE_HANDLER_H
      
      
      UpdateHandler::UpdateHandler(QObject* parent)
          :QObject(parent)
      {
          updEnc = new QFile("/media/upStick/update.enc");
          cpscript <<"/usr/bin/cpupdt.sh";
          file = new QFile("/usr/update.enc");
          copy  = new QProcess(this);
          QObject::connect(copy, SIGNAL(finished(int)), this, SLOT(fileCopied(int)));
          QObject::connect(copy, SIGNAL(errorOccurred(QProcess::ProcessError)), this, SLOT(errorFound(QProcess::ProcessError)));
      }
      void UpdateHandler::fileSearch(){
          if(updEnc->exists()){
              qDebug()<< "Updatefile found on Stick";
              qDebug()<< "copying file to /usr";
              copy->start("/bin/sh", cpscript);
              }else{
              qWarning()<< "no update found at UpdateStick/or no Stick insert";
              emit updateFailed();
          }
      }
      void UpdateHandler::fileCopied(int status){
          qWarning()<< copy->errorString();
          copy->close();
          if(status==0){
              if(file->exists())
              {
                  qDebug()<< "sucess",
                  emit updateSuccess();
      
              }else{
                  qWarning()<< "no update.enc found in /usr";
                  emit updateFailed();
              }
          }else{
              qWarning()<< "/usr/bin/cpupdt.sh crashed ";
              emit updateFailed();
      
          }
      }
      void UpdateHandler::errorFound(QProcess::ProcessError e){
          QString filename="/var/ziesel/update.txt";
          QFile log( filename);
          qDebug()<< "Error during Update: "<< e ;
          if ( log.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Unbuffered | QIODevice::Text) )
          {
              QTextStream stream(&log);
              stream << "Error:" << e << endl;
              log.close();
          }
      }
      

      I know i have only finished(int) , instead of finished(int, QProcess::ExitStatus);
      But i have qt 5.6 on my device and i wasn´t sure which to use, but i tried both.

      1 Reply Last reply
      0
      • L Offline
        L Offline
        LogiSch17
        wrote on last edited by LogiSch17
        #6

        So for everyone who is interrested. I found what was causing the missbehavoir
        I had a Qprocess in a constructer of a other class. Which makes the handshake for a CAN controller.
        This here:

        QProcess * canup;
        canup = new QProcess(this);
        QStringList args;
        args << "can0" << "up";
        canup->start("ifconfig", args);

        When i comment this out everything works.
        But i don´t know why this is happening.

        A 1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #7

          I guess it's not likely but does your copy script depends on the can bus interface to be up ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • L LogiSch17

            So for everyone who is interrested. I found what was causing the missbehavoir
            I had a Qprocess in a constructer of a other class. Which makes the handshake for a CAN controller.
            This here:

            QProcess * canup;
            canup = new QProcess(this);
            QStringList args;
            args << "can0" << "up";
            canup->start("ifconfig", args);

            When i comment this out everything works.
            But i don´t know why this is happening.

            A Offline
            A Offline
            ambershark
            wrote on last edited by
            #8

            @LogiSch17 said in QProcess doesn´t emit finished() when done:

            So for everyone who is interrested. I found what was causing the missbehavoir
            I had a Qprocess in a constructer of a other class. Which makes the handshake for a CAN controller.
            This here:

            QProcess * canup;
            canup = new QProcess(this);
            QStringList args;
            args << "can0" << "up";
            can0->start("ifconfig", args);

            When i comment this out everything works.
            But i don´t know why this is happening.

            That's interesting... Does your canup finish and get cleaned up properly before you are trying with the next QProcess? Just curious, it's not like you can't have multiple QProcesses at any given time.

            Are these QProcesses in different threads?

            Do you get the signals from the canup process properly?

            My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

            1 Reply Last reply
            0
            • L Offline
              L Offline
              LogiSch17
              wrote on last edited by
              #9

              Hi, sry have been sick.

              First, no the copy script doesm´t depend on the can bus interface.
              And second:
              For the can up , i have never tried to get the finished signal. But i tried
              canup->wait ForFinished();
              Which seems to work cause there is no delay during the can initialisation.
              And yes the QProcesses are in different threads, or in different QObjects.

              A 1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #10

                So if you ensure can0 is finished before starting the next QProcess, everything is running fine ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • L LogiSch17

                  Hi, sry have been sick.

                  First, no the copy script doesm´t depend on the can bus interface.
                  And second:
                  For the can up , i have never tried to get the finished signal. But i tried
                  canup->wait ForFinished();
                  Which seems to work cause there is no delay during the can initialisation.
                  And yes the QProcesses are in different threads, or in different QObjects.

                  A Offline
                  A Offline
                  ambershark
                  wrote on last edited by
                  #11

                  @LogiSch17 So what if after you start your process you immediately do copy->waitForFinished(). Will that ever return?

                  My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    LogiSch17
                    wrote on last edited by
                    #12

                    @SGaist No even if i wait i have the can0-> waitForFinished(), all the following QProcesses are not returning.
                    do i have to close something?

                    @ambershark I allready tried but, it stays for the default 30000msecs, but afterwards nothing has been returned.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #13

                      Did you check the content of the standard error and standard output of all your QProcess ? There might be a clue there to what is happening.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • L Offline
                        L Offline
                        LogiSch17
                        wrote on last edited by
                        #14

                        yes i did. got nothing.
                        Currently i removed the ifconfig QProccess from my code and run it as script in init.d before running my programm.
                        Now everything works fine.
                        Look´s like QProccess has problems with the ifconfig command.

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #15

                          Can you provide a minimal code sample that triggers that ?

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          0
                          • L Offline
                            L Offline
                            LogiSch17
                            wrote on last edited by
                            #16

                            i got something like

                                QStringList arguments;
                                arguments << "can0" << "up";
                                QProcess::execute("ifconfig",  arguments );
                            
                            

                            but i had it allready with finished() and errorOccured() signals conected to slots -> same result.
                            I would say my buildroot generated OS makes the problem.

                            1 Reply Last reply
                            0
                            • SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on last edited by
                              #17

                              Really surprising. If you call any other command, do you have the same problem ?

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              0
                              • L Offline
                                L Offline
                                LogiSch17
                                wrote on last edited by
                                #18

                                No never seen the problem before , and i have a lot of qproccess in my code. From shutdown , reboot, mv , cp to a lot of scripts .

                                1 Reply Last reply
                                0
                                • SGaistS Offline
                                  SGaistS Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #19

                                  Is it only on your device or can you reproduce that on your desktop machine ?

                                  Interested in AI ? www.idiap.ch
                                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  1 Reply Last reply
                                  0
                                  • L Offline
                                    L Offline
                                    LogiSch17
                                    wrote on last edited by
                                    #20

                                    On my desktop machine it works fine. But i have no CAN device their.
                                    So i returns that can0 device not exists and goes on normaly. But the the other proccesses are working afterwards.

                                    1 Reply Last reply
                                    0
                                    • SGaistS Offline
                                      SGaistS Offline
                                      SGaist
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #21

                                      Since the can bus is a network device, did you try calling ifconfig up on another device ? That might help narrow down the problem.

                                      Interested in AI ? www.idiap.ch
                                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                      1 Reply Last reply
                                      0
                                      • L Offline
                                        L Offline
                                        LogiSch17
                                        wrote on last edited by
                                        #22

                                        No didn´t tried yet. I have it fixed now by running a startup script . Which does exatly the same.
                                        But i will have a look at this problem again when i have some more time. I will let you know if i find out something.

                                        1 Reply Last reply
                                        0
                                        • L LogiSch17

                                          i always start my scripts with:

                                          process->start("/bin/sh", QStringList << "/path/to/my
                                          script.sh");
                                          

                                          when i try to start ls it does not work either.

                                          B Offline
                                          B Offline
                                          bisou
                                          wrote on last edited by
                                          #23

                                          @LogiSch17 I had a similar problem in that no QProcess::finished() signals were being emitted. The problem was SOLVED by not catching the Unix signal SIGCHLD, which implies that this signal is being used by QProcess to communicate between parent and child processes. Maybe this was your problem too.

                                          JonBJ 1 Reply Last reply
                                          0

                                          • Login

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