Reload signal function, to solve the problem parameters

In QT, we signal functions and parameter matching slot function is required, only the parameter matching, moc these two functions can be linked, otherwise the compiler will not be able to tell which of the function call.

So if there is a signal function it has two different parameters, how we need to affirm the slot function do?
In the QT4, our connection using two different macros defined parameter type and we can explicitly specify that we need, but in the QT5, we are not using macro definitions, we declare a connection to the following :

QObject::connect(*sender,&signal,*receiver,&slot);

 

It became apparent that we can not give the type of parameters we need to display in a statement, then the next in order to solve the problem overloaded with different parameters, what we need is an explicit pointer function to create a signal is given directly below examples of such currentIndexChaned I need to process the signal QComBox, this signal has two parameters, one is QString, and the other is int, int this signal we need to use the function:

void (QComboBox::*fun)(int) = &QComboBox::currentIndexChanged;
QObject::connect(comboBox,fun,*receiver,&slot);

 

In this way, we passed to the signal slot function is int type, and also solves the problem of overloading signal function.



Guess you like

Origin www.cnblogs.com/lixuejian/p/11004607.html