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 ofReceiveData
I 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.
ReceiveData
is 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 classConverter
is derived fromQObject
.void Converter::ConvertData(Datatype* data) { //... Converting stuff ... emit SendConvertedData(m_convertedData); }
Than the third class
StoreData
implements 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
StoreData
the call ofCopyData
did not work. But when I move the last connect function to the classReceiveData
the slotCopyData
gets 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 ?
-
@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
,ConvertData
andStoreData
runs in the same thread, in detail in the main thread. The classWorker
that 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_worker
is initialized. I addqDebug
to the slotsPublishData
andConvertData
and 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
ReceiveData
but not in in theStoreData
class.
m_converter is also initialized. Setting the connection type toQt::Autoconnection
does 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
this
where 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. -
Problem solved. Thanks for your advices!