Answer the question
In order to leave comments, you need to log in
Is it possible in Qt to connect signals with different parameters to one single slot?
Good day!
There are several signals with different types of parameters and different number of them.
It is not possible to change the signal declarations themselves.
It is necessary to connect them all with one slot in which one could get all these parameters, how can (and can) this be implemented?
I know the signal parameters and their types - I can get a string representation in order to write SIGNAL (...) only as a string.
So far, I realized that the simplest thing is that the slot would have no parameters at all, then it can be connected to any signal. Through QObject::sender found who sent the signal. But how to get the parameters now?
If not, how would it be more elegant to get around this limitation without creating a bunch of slots?
Answer the question
In order to leave comments, you need to log in
Do you only connect using SIGNAL() SLOT() strings?
Here is a variant for the new connection method:
If all options can be converted to QVariant and C++11 is used, you can try something like this:
signals:
void someSignal1(QString a);
void someSignal2(int a, QString b);
void someSignal3(float a, int b, QString c);
...
void someSlot(QVariant arg1,QVariant arg2, QVariant arg3);
connect(sender, &Sender::someSignal1, std::bind( &Receiver::someSlot, receiver, std::placeholders::_1, QVariant(), QVariant() ));
connect(sender, &Sender::someSignal2, std::bind( &Receiver::someSlot, receiver, std::placeholders::_1, std::placeholders::_2, QVariant()));
connect(sender, &Sender::someSignal3, std::bind( &Receiver::someSlot, receiver, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3 ));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question