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 18.5k 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.
  • L Offline
    L Offline
    LogiSch17
    wrote on last edited by
    #1

    Hi ,
    I have the same problem as allready descriped in this old post here.
    Re: QProcess doesn't emit finished signal when script completes its execution

    Notice that the code is working on my arch desktop and i also tried on a debian based linux, which also worked.

    I try to run the programm on a RaspberryPi Compute Module with a small buildroot created, busybox linux with kernel version 4.3.

    The problem is that when i start a QProccess it never emits me the finished signal.
    When i try process->waitForFinished() it doesn´t work either. It simply waits the default 30000msecs.

    The script i am executing is a simple test script like:

    #!/bin/sh
    LOG="/usr/log.txt"
    echo "Test1... " >> $LOG
    echo "Test2... " >> $LOG
    ..
    exit 0
    

    and I know the script has been exectued cause the logfile has been nicely writen
    .
    So i would say it is not a problem of QT.
    But I have no idea how to fix it .
    So I tought that the experts here, which know where QProcess get´s the messages from can help me.
    Or anyone had the same problem in meantime and had allready fixed it?

    I would be very grateful for any advice.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      ambershark
      wrote on last edited by
      #2

      If you are executing the shell script directly try passing it through sh or bash, i.e.

      bash myscript.sh or sh myscript.sh

      Then when the script completes it should exit the shell and cause the finished signal to be emitted.

      My guess on this is that it is running the shell script in some sort of persistent shell that is running on the OS and therefore never exits the process in order to get the finished signal.

      Also if that doesn't work try running an actual executable like ls and see if the finished signal is emitted. If not it may be a problem with the Pi and that should at least give you more info to google or a bug report to file.

      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
        #3

        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 1 Reply Last reply
        0
        • 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

                                          • Login

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