The connection between the CITIC number and the slot in Qt5 has some changes to Qt4.
The connection method in Qt4 is similar to this:
QObject::connect(const QObject * sender, const char * signal, const QObject * receiver, const char * method, Qt::ConnectionType type = Qt::AutoConnection)
Qt5 is like this:
QObject::connect(const QObject * sender, PointerToMemberFunction signal, const QObject * receiver, PointerToMemberFunction method, Qt::ConnectionType type)
In Qt5, class names are used directly to use signal/slot functions.
Assume that two signals are defined in my class:
signals: void mysignal(int iNum); void mysignal(int iNum, const QString& str);
We can see that these two signal functions are actually overload functions.
In Qt4, this does not cause any problems:
connect(this, SIGNAL(mysignal(int)), this, SLOT(mySlot()));connect(this, SIGNAL(mysignal(int, QString)), this, SLOT(mySlot()));
He can specify which signal we send.
But in Qt5, it is different:
connect(this, &XXX::mysignal, this, &XXX::mySlot);
In this way, what we send is
mysignal(int iNum);
Or
mysignal(int iNum, const QString& str);
This will lead to ambiguity. How can we solve this problem?
We can use the function pointer to differentiate the two signal functions:
void (XXX::*mynewsignal) (int iNum, const QString& str) = &XXX::mysignal;
Call again:
connect(this, &XXX::mysignal, this, &XXX::mySlot);connect(this, &XXX::mynewsignal, this, &XXX::mySlot);
In this way, we can identify which signal we send.