c++qtqt-signalsslotqsignalmapper

QObject::connect fails at runtime, while linking thread's finished-signal to mapper's delateLater-slot


i'm using C++ and Qt4.5.2 (requirement of the target system) in my project. There is a need of a worker thread supplied with additional arguments/parameter, so i did the following (in short with deleted error handling/output):

bool _bRetVal = false;
COpgThread* _pParseThread = new COpgThread(); // COpgThread is subclassed from QThread to access the protected msleep-function
COpgWorker* _pParseWorker = new COpgWorker(); // COpgWorker is subclassed from QObject to provide: slots (process) and signals (finished, progress, error) for a COpgThread-instance
QSignalMapper* _pParseMapper = new QSignalMapper();
COpgParam _pParseParam = new COpgParam(m_sParseFile, m_sRegExpFile); // COpgParam is subclassed from QObject to handle user data for mapping

_pParseWorker->moveToThread(_pParseThread);
//#1 hookup error-signal from worker to errorParsing-function in this object
_bRetVal = QObject::connect(_pParseWorker, SIGNAL(error(int const)), this, SLOT(errorParsing(int const)));

//#2..3 hookup thread's started-signal to process-slot in the worker (via signal mapper for parameters/arguments)
_bRetVal = QObject::connect(_pParseThread, SIGNAL(started()), _pParseMapper, SLOT(map()));
_pParseMapper->setMapping(_pParseThread, _pParseParam);
_bRetVal = QObject::connect(_pParseMapper, SIGNAL(mapped(QObject*)), _pParseWorker, SLOT(process(QObject*)));

//#4 hookup progress-signal from worker to progessParsing-function in this object    
_bRetVal = QObject::connect(_pParseWorker, SIGNAL(progress(int const)), this, SLOT(progressParsing(int const)));

//#5 hookup finished-signal from worker to completedParsing-function in this object
_bRetVal = QObject::connect(_pParseWorker, SIGNAL(finished(int const)), this, SLOT(completedParsing(int const)));

//#6 when worker emits finished-signal, signal thread to quit (shutdown)
_bRetVal = QObject::connect(_pParseWorker, SIGNAL(finished(int const)), _pParseThread, SLOT(quit()));
//#7 when worker emits finished-signal, mark worker to be deleted
_bRetVal = QObject::connect(_pParseWorker, SIGNAL(finished(int const)), _pParseWorker, SLOT(deleteLater()));
//++++ this connect fails at runtime ++++
    //#8 when thread emits finished-signal, mark mapper to be deleted
    _bRetVal = QObject::connect(_pParseThread, SIGNAL(finished(int const)), _pParseMapper, SLOT(deleteLater()));
//+++++++++++++++++++++++++++++++++++++++
//#9 when thread emits finished-signal, mark thread to be deleted
_bRetVal = QObject::connect(_pParseThread, SIGNAL(finished(int const)), _pParseThread, SLOT(deleteLater()));
_pParseThread->start();

The whole code compiles without any errors, but the 8th connect fails at runtime. I thought, that when i create an instance of QSignalMapper ... it has to bee deleted sometime or other. Maybe it's wasted code. I'm not that familiar with Qt.

Any suggestions?

Thanks in advance.


Solution

  • but the 8th connect fails at runtime.

    An error message is printed to stdout - what does it print?

    btw: The QProcess::finished() signal is SIGNAL(finished(int)) - this might be your problem.