Qt already provides signals and slots for its classes, which you can use in your application. And even between objects living inside different threads; Keep in mind that to be able to connect a signal to a slot, their methods' signatures must match.
Hi,
lets say i have a Class Data:
@
class Data public QObject
{
public slots:
QString getName()
{
QString sTmp = 'My Name is Stiffler';
return sTmp;
};
}
@
I have antother Class:
@
class A public QObject
{
signals:
QString getNameFromData();
}
@
I connet the Signal 'getNameFromData' with the Slot 'getName()' from Data.
@
//This Code is somewhere in class A
qDebug() << 'Name of Class Data:' << getNameFromData();
@
Understanding Signals and Slot in Qt is not very difficult. Signals and slots are the basic foundation of Qt C GUI Application. In this QT tutorial we will learn signal and slots tutorial. A signal is defined in the signals section A signal always returns void A signal must not be implemented The moc provides an implementation A signal can be connected to any number of slots Usually results in a direct call, but can be passed as events between threads, or even over sockets (using 3 rd party classes) The slots are activated in.
This gives:
Name of Class Data: 'My Name is Stiffler'
So I thought handling signals and slots with non void return values would be no problem at all.
But as I moved class Data to another Thread then class A, suddenly the code gives:
Name of Class Data: '
Signal And Slot In Qt
So the Return Value seems like just not received.
Can someone tell me if this is 'normal' QT behaivior? Im I doing or understanding something wrong?
Hello all !
I have some difficulties to find an appropriate way to solve a problem of communication between objects in differents threads (although I already read the Signals/slots accross threads). Here is my problem:
I have an object a of class A living in a thread T1.
I have an object b of class B living in a thread T2.
Both objects a and b can emit signals and have slots to manage the signals emitted by the object living in the other thread (Object a has slots to manage signals from object b, and object b have slots to manage signals from object a).
Qt Debug Signal And Slot
Once I have moved the object to their respective threads, I connect the signals/slots using Qt::connect(..., Qt::QueuedConnection), but once the signals is emitted, the slot is never executed.
I don't use Qt::DirectConnection (because it's quite the same that invoking directly the method, and I don't want this), and I would like to avoid to manage an event dispatcher or an event loop in the parent thread.
Does someone know how to use correctly the Qt threads in order to make the communication between signals/slots between objects living in different threads (none living in the main thread) ?
Thank you a lot for your answers !