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 executionNotice 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.
-
If you are executing the shell script directly try passing it through
sh
orbash
, i.e.bash myscript.sh
orsh 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. -
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.
-
Hi,
i gotQObject::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. -
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. -
I guess it's not likely but does your copy script depends on the can bus interface to be up ?
-
@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. -
So if you ensure can0 is finished before starting the next QProcess, everything is running fine ?
-
@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.
-
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.
-
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. -
Really surprising. If you call any other command, do you have the same problem ?
-
Is it only on your device or can you reproduce that on your desktop machine ?