Slot gets not invoked
-
Hi,
I had thought, I understand signals and slots, but there is a problem I did not get solved. I would like to give a short overview:
I have three classes. In the constructor ofReceiveDataI implement two connect functions which send data from worker to a slot:ReceiveData::ReceiveData(QWidget* parent) { QObject::connect(m_worker, &Worker::SendData, this, &ReceiveData::PublishData, Qt::QueuedConnection); QObject::connect(m_worker, &Worker::SendData, m_convertData, &Converter::ConvertData, Qt::QueuedConnection); }Calling slots in these class works.
ReceiveDatais derived fromQWidget.I have another worker class, named
Converter. Here I implement a slot thats converts my data. This slot also emits a signal that sends the converted data to a slot in another class, namedStoreData. The classConverteris derived fromQObject.void Converter::ConvertData(Datatype* data) { //... Converting stuff ... emit SendConvertedData(m_convertedData); }Than the third class
StoreDataimplements the connect function like this and is also derived fromQWidget:QObject::connect(m_converter, &Converter::SendConvertedData, this, &StoreData::CopyData, Qt::DirectConnection);So the converted data is send to a slot which copied the data. And here is the problem, because in the class
StoreDatathe call ofCopyDatadid not work. But when I move the last connect function to the classReceiveDatathe slotCopyDatagets invoked.
All classes runs in the same thread, so I did not understand why there is a problem. -
QObject::connect(m_converter,...
Are you sure this instance really emits the signal and not another one?
All classes runs in the same thread,
Why the QueuedConnection and DirectConnection then? Not needed...
ConvertData(T* data)
Template class? How did you solve the problem with Q_OBJECT macro there?
-
Hi,
In addition to @Christian-Ehrlicher, is
@makopo said in Slot gets not invoked:m_worker
properly initialized ?
-
QObject::connect(m_converter,...
Are you sure this instance really emits the signal and not another one?
All classes runs in the same thread,
Why the QueuedConnection and DirectConnection then? Not needed...
ConvertData(T* data)
Template class? How did you solve the problem with Q_OBJECT macro there?
@Christian-Ehrlicher said in Slot gets not invoked:
Are you sure this instance really emits the signal and not another one?
Why the QueuedConnection and DirectConnection then? Not needed.ReceiveData,ConvertDataandStoreDataruns in the same thread, in detail in the main thread. The classWorkerthat send the raw data runs ins an seperate thread.Template class? How did you solve the problem with Q_OBJECT macro there?
No template class. I wrote T to mark any data type.
@SGaist said in Slot gets not invoked:
m_worker
properly initialized ?
m_workeris initialized. I addqDebugto the slotsPublishDataandConvertDataand can see that this connection works.
There is only a problem with this connection:QObject::connect(m_converter, &Converter::SendConvertedData, this, &StoreData::CopyData, Qt::DirectConnection);that runs in the class
ReceiveDatabut not in in theStoreDataclass.
m_converter is also initialized. Setting the connection type toQt::Autoconnectiondoes not show a positive result. -
@makopo said in Slot gets not invoked:
m_converter is also initialized.
This was not the question - the question was if this is really the object where you do the emit or if there is another one around. Please add a debug statement to print out the address of m_converter there and
thiswhere you do the emit to check if they're the same. I would guess they're not. -
@makopo said in Slot gets not invoked:
m_converter is also initialized.
This was not the question - the question was if this is really the object where you do the emit or if there is another one around. Please add a debug statement to print out the address of m_converter there and
thiswhere you do the emit to check if they're the same. I would guess they're not.@Christian-Ehrlicher
Thanks for the advice. I will check this in the afternoon. -
@makopo said in Slot gets not invoked:
m_converter is also initialized.
This was not the question - the question was if this is really the object where you do the emit or if there is another one around. Please add a debug statement to print out the address of m_converter there and
thiswhere you do the emit to check if they're the same. I would guess they're not.