QProcess doesn´t emit finished() when done

  • 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:

    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.

  • Moderators

    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.

  • i always start my scripts with:

    process->start("/bin/sh", QStringList << "/path/to/my

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

  • Lifetime Qt Champion


    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.

  • 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.


    #ifndef UPDATE_HANDLER_H
    #define UPDATE_HANDLER_H
    #include <QtCore/QObject>
    #include <QProcess>
    #include <QFile>
    #include <QStringList>
    #include <QProcess>
    class UpdateHandler : public QObject
            UpdateHandler(QObject* parent = nullptr);
            void updateSuccess();
            void updateFailed();
        private slots:
            void fileSearch();
            void fileCopied(int);
            QFile* file;
            QFile* updEnc;
            QStringList cpscript;
            QProcess* copy;
            QString filename;
            QFile log;
    #endif // UPDATE_HANDLER_H
    UpdateHandler::UpdateHandler(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(){
            qDebug()<< "Updatefile found on Stick";
            qDebug()<< "copying file to /usr";
            copy->start("/bin/sh", cpscript);
            qWarning()<< "no update found at UpdateStick/or no Stick insert";
            emit updateFailed();
    void UpdateHandler::fileCopied(int status){
        qWarning()<< copy->errorString();
                qDebug()<< "sucess",
                emit updateSuccess();
                qWarning()<< "no update.enc found in /usr";
                emit updateFailed();
            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;

    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.

  • 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.

  • Lifetime Qt Champion

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

  • Moderators

    @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?

  • 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.

  • Lifetime Qt Champion

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

  • Moderators

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

  • @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.

  • Lifetime Qt Champion

    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.

  • 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.

  • Lifetime Qt Champion

    Can you provide a minimal code sample that triggers that ?

  • 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.

  • Lifetime Qt Champion

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

  • 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 .

  • Lifetime Qt Champion

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

  • 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.

  • Lifetime Qt Champion

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

  • 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.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.