The connect (m_udpSocket, SIGNAL (readyRead ()), and this, SLOT (on_receiveUDP ()));
The two supposedly effect is the same, but the above will not be able to start slot function, the following can be, this is how to return a responsibility?
CodePudding user response:
The connect (m_tcpSocket, & amp; QUdpSocket: : readyRead, this, & amp; Connect: : on_receiveUDP);M_tcpSocket is a QTcpSocket object, of course, can not find a QUdpSocket: : readyRead the function pointer,
To try the following:
The connect (m_tcpSocket, & amp; QTcpSocket: : readyRead, this, & amp; Connect: : on_receiveUDP);
CodePudding user response:
There is a difference between these two approaches, you can look to the relevant technical documents, using function pointer mode pattern above the parameters of the signals and slots strict match! And the way that using the macro definition allows signals and slots parameters not strictly match, a simple example: button clicked signals is a parameter, but if you use the macro signal slot connection, you can define a slot function without parameters, and the connection is successful, so although you written above also look for, in fact, signals and slots parameters do not matchCodePudding user response:
Please refer to the following technical documentation:Differences between the String - -based and Functor - -based Connections
The From Qt 5.0 onwards, Qt offers two company's ways to write signal - slot connections in c + + : The string - -based connection syntax and The functor - -based connection syntax. There are pros and cons to both syntaxes. The table below summarizes their differences.
String - -based
Functor - -based
The Type checking is done at...
The Run - time
The Compile - time
Can perform implicit type conversions
Y
Can connect signals to lambda expressions
Y
Can connect signals to slots which have more arguments than the signal (using the default parameters)
Y
Can connect the c + + functions provides the to QML functions provides
Y
The following sections explain these differences in detail and demonstrate how to use The features unique to each connection syntax.
The Type Checking and Implicit Type Conversions
String - -based connections type - check by comparing strings at run - time. There are three limitations with this approach:
Connection errors can only be detected after the program has started running.
Implicit conversions always be done between signals and slots.
Typedefs and namespaces always be resolved.
Limitations of 2 and 3 exist because the string comparator does not have access to a c + + type information, so it relies on exact string matching.
In contrast, functor - -based connections are checked by the compiler. The compiler catches errors at compile time, enables implicit conversions between compatible types, and recognizes the company names of the same type.
For example, only the functor - -based syntax can be 2 connect a signal that carries an int to a slot that accepts a double a QSlider doesn an int value while a QDoubleSpinBox doesn a double value. The following snippet shows how to keep them in sync:
CodePudding user response:
In favor of the second floor, the first parameter is the QTcpSocket connect function, then the second parameter should be QTcpSocket: : readyRead ()CodePudding user response:
Should write the wrong is not careful