I already have an application in place and am tweaking it now. In this regard, I am introducing a new signal, which has to be emitted when another signal is emitted. Is this possible in Qt?
Writing a slot just to emit this signal feels so primitive and lame...
Detailing further, I have to connect the button signalClicked() to my own signal say sendSignal(enumtype)...
EDIT: Forgot to mention that I need to send a data with the second signal.
This ensures that truly independent components can be created with Qt. You can connect as many signals as you want to a single slot, and a signal can be connected to as many slots as you need. It is even possible to connect a signal directly to another signal.
Signals are neither synchronous nor asynchronous. It's the slots that might be one of the two. Slots are by default synchronous when the object emitting the signal and the object having the receiving slot both live in the same thread.
[static] QMetaObject::Connection QObject::connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type = Qt::AutoConnection) Creates a connection of the given type from the signal in the sender object to the method in the receiver object.
Yes, it is possible without creating additional slot. Just connect signal to signal:
connect(this,SIGNAL(someSignal()),this,SIGNAL(anotherSignal()));
More information in doc.
Edit:
You can share data in connection as usual. Dirty example:
QWidget* obj = new QWidget;
obj->setWindowTitle("WindowTitle");
//share data, pass wrong data to the signal
QObject::connect(obj,SIGNAL(objectNameChanged(QString)),obj,SIGNAL(windowTitleChanged(QString)));
QObject::connect(obj,&QWidget::windowTitleChanged,[](QString str) {qDebug() << str;});
obj->setObjectName("ObjectName");
qDebug() << "But window title is"<< obj->windowTitle();
obj->show();
Output is:
"ObjectName"
But window title is "WindowTitle"
But there is no way to do something like:
connect(this,SIGNAL(someSignal()),this,SIGNAL(anotherSignal("with custom data")));
In this case, you need a separate slot.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With