Qprocess in thread
-
In .h file
QProcess *m_pRsyncprocess;
In .cpp
void FileReceiverThread::run()
{
// thread starts here
qDebug() << " Thread started";socket = new QTcpSocket(); // set the ID if(!socket->setSocketDescriptor(this->socketDescriptor)) { // something's wrong, we just emit a signal emit error(socket->error()); return; } // connect socket and signal // note - Qt::DirectConnection is used because it's multithreaded // This makes the slot to be invoked immediately, when the signal is emitted. connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead()), Qt::DirectConnection); connect(socket, SIGNAL(disconnected()), this, SLOT(disconnected())); // We'll have multiple clients, we want to know which is which qDebug() << socketDescriptor << " Client connected"; m_pRsyncprocess = new QProcess(); QObject::connect(m_pRsyncprocess, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(RsyncProcessfinished(int,QProcess::ExitStatus))); QObject::connect(m_pRsyncprocess, SIGNAL(started()), this, SLOT(RsyncProcessstarted())); // make this thread a loop, // thread will stay alive so that signal/slot to function properly // not dropped out in the middle when thread dies exec();
}
void FileReceiverThread::RsyncProcessfinished(int exitCode, QProcess::ExitStatus exitStatus)
{
qDebug() << "RsyncProcessFinished: " << exitCode << "exitStatus:" << exitStatus;QProcess *p = qobject_cast<QProcess*>(sender()); qDebug() << "p->exitCode():" << p->exitCode() << "exitStatus:" << exitStatus; if(p->exitCode() == 0) { qDebug() << "########### File Received Sucessfully #################" /*<< sEdgeserverId << ip4String*/; socket->write("File Received Sucessfully"); exec(); } else if(p->exitCode() == 1 || p->exitCode() == 2) { qDebug() << "########### Syntax error (or) Protocol incompatibility #################" /*<< sEdgeserverId << cli_addr.toString()*/ ; } else if(p->exitCode() == 3) { qDebug() << "########### Errors selecting input/output files, dirs #################" /*<< sEdgeserverId << cli_addr.toString()*/ ; } else if(p->exitCode()== 23 || p->exitCode() == 24) { qDebug() << "########*/### Partial transfer due to error (or) Partial transfer due to vanished source files #################" /*<< sEdgeserverId << cli_addr.toString()*/ ; }
}
in this line QProcess p = qobject_cast<QProcess>(sender()); it is chrashing can anybody tell what is problem.any give me solution to solve.
-
And once again - makeing something complicated because of using a thread for no good reason...
but anyway: since you already have a member m_pRsyncprocess - why do you need to do an qobject_cast<> there at all instead simply accessing the member?btw: Where do you clean up m_pRsyncprocess and socket ?
-
This post is deleted!
-
m_pRsyncprocess running rsync commands that is not giving exact exitcode of rsync command.
QProcess p = qobject_cast<QProcess>(sender());
it is giving correct exit code of rsync
-
@satyanarayana143 Then you're doing a lot of stuff wrong - m_pRsyncprocess and QProcess p = qobject_cast<QProcess>(sender()); must return the same pointer...
And previously you told me that the qobject_cast<> was crashing, now you're telling me that the return code of the pointer retrieved by qobject_cast<> is different to what m_pRsyncprocess is returning... how can you know when the qobject_cast<> is crashing?? -
@satyanarayana143 said in Qprocess in thread:
QProcess p = qobject_cast<QProcess>(sender());
with out calling
QProcess p = qobject_cast<QProcess>(sender());
the exitcode is not of rsync exit code.
if i call it is crashing
QProcess p = qobject_cast<QProcess>(sender());
-
@satyanarayana143 said in Qprocess in thread:
the exitcode is not of rsync exit code.
How do you know?
-
if rsync command in terminal for error some exitcode is coming and for proper execution exitcode is different
but with Qporcess if error comes also exitcode is coming proper execution exitcode also same
-
So did you actually check if you pass the same parameter on the command line and in your program?
-
yes i am giving same command in terminal and for Qprocess
-
@satyanarayana143 said in Qprocess in thread:
if rsync command in terminal for error some exitcode is coming and for proper execution exitcode is different
but with Qporcess if error comes also exitcode is coming proper execution exitcode also sameNo idea what this means? I don't believe you will see different behaviour in
rsync
depending on whether you run from terminal or viaQProcess
. Show running it from terminal and code for running it from Qt app. -
@satyanarayana143 said in Qprocess in thread:
yes i am giving same command in terminal and for Qprocess
I don't believe this - esp. since you did not post the code for it.