Qt-interest Archive, January 2007
Signaling across threads
Message 1 in thread
I am converting an application from Qt3, and the following used to work
but now does not. I have a QDialog-derived class that starts a file read
operation in its start_extract_binary method (RawDataMap is a class
derived from QThread. The extract_binary() method calls start() to drop
into the run() method).
std::ifstream binis;
binis.open(fn, ios_base::binary);
m_RawDataMap.SetDoneRecvr(this);
m_RawDataMap.extract_binary(binis);
At the end of the run() method of RawDataMap, I sent a custom event back
to the QDialog-based object:
qApp->postEvent((QObject *)m_pRecvr, new FileReadDoneEvent());
Back in the QDialog, i look for the FileReadDoneEvent in the customEvent
method:
if ( ev->type() == BIPS_FILEREADDONE_EVENT)
{
finishExtractBinary();
return;
}
In Qt3 this worked fine, the finishExtractBinary method got called and
the QDialog proceeded to display the data. In Qt4, the customEvent
method is never called.
I have modified the RawDataMap for Qt4 by adding a slot to receive the
finished() signal, I added this line in the top of the run() method:
connect(this,SIGNAL(finished()),this,SLOT(finishFileIO()));
The code that was at the end of the run() method to send the customEvent
is now moved to finishFileIO(), so it should be outside of the run() method.
Then in the finishFileIO() method, I added the following:
moveToThread(QApplication::instance()->thread());
qApp->postEvent((QObject *)m_pRecvr, new FileReadDoneEvent());
The customEvent back in the QDialog (m_pRecvr points to that...) is
still not called.
I have read a previous thread in this newsgroup related to signals and
threads, but cant quite make it apply to this situation. Can anyone
provide more suggestions?
Thanks ahead...
--
[ signature omitted ]
Message 2 in thread
Hi,
> Back in the QDialog, i look for the FileReadDoneEvent in the customEvent
> method:
> if ( ev->type() == BIPS_FILEREADDONE_EVENT)
> {
> finishExtractBinary();
> return;
> }
Can you show us the whole customEvent() method?
Note that the signature seems to have changed from:
QObject::customEvent(QCustomEvent *)
to:
QObject::customEvent(QEvent *)
--
[ signature omitted ]
Message 3 in thread
Dimitri wrote:
> Hi,
>
>> Back in the QDialog, i look for the FileReadDoneEvent in the
>> customEvent method:
>> if ( ev->type() == BIPS_FILEREADDONE_EVENT)
>> {
>> finishExtractBinary();
>> return;
>> }
>
> Can you show us the whole customEvent() method?
>
> Note that the signature seems to have changed from:
> QObject::customEvent(QCustomEvent *)
> to:
> QObject::customEvent(QEvent *)
>
> --
> Dimitri
Welllll, sometimes it is silly things. I changed
customEvent(QCustomEvent *) to customEvent(QEvent *) and it ran like a
charm!
thanks Dimitri
--
[ signature omitted ]