Full examples with New_Signal_Slot_Syntax
-
Hello Qt Community
I was working through a simple example that uses the old Qt signal and slot macros:
SIGNAL(), SLOT ()
using the macros in params 2 and 4 in connect as follows:
connect(
sender, SIGNAL( valueChanged( QString, QString ) ),
receiver, SLOT( updateValue( QString ) )
);However, a lot of the documentation has no been updated to show us how to use examples using the new method, where the const * char parameters in positions 2 and 4 are replaced with the following
connect(
sender, &Sender::valueChanged,
receiver, &Receiver::updateValue
);Is there a more complete example that includes definition of the "PointerToMemberFunction" signal and method ?
-
Yes, but the example in https://wiki.qt.io/New_Signal_Slot_Syntax is incomplete.
How do you define Sender and Receiver as PointerToMemberFunctions
connect(
sender, &Sender::valueChanged,
receiver, &Receiver::updateValue
);assume you want to connect the textChanged signal from a QlineEdit with a QLabel
QLineEdit *lineEdit = new QLineEdit(); //Sender Object/Instance QLabel *label = new QLabel(); //Receiver Object/InstanceQLineEdit has the textChanged signal:
QLineEdit::textChangedQLabel has the slot
setText:
QLabel::setText//connect(senderObject, pointer to signal, receiver, pointer to slot); connect(lineEdit, &QLineEdit::textChanged, label, &QLabel::setText); -
What's wrong with the Qt documentation? What are you missing exactly?
-
Hi
Did you also see this ?
https://wiki.qt.io/New_Signal_Slot_Syntax -
Yes, but the example in https://wiki.qt.io/New_Signal_Slot_Syntax is incomplete.
How do you define Sender and Receiver as PointerToMemberFunctions
connect(
sender, &Sender::valueChanged,
receiver, &Receiver::updateValue
); -
Yes, but the example in https://wiki.qt.io/New_Signal_Slot_Syntax is incomplete.
How do you define Sender and Receiver as PointerToMemberFunctions
connect(
sender, &Sender::valueChanged,
receiver, &Receiver::updateValue
);@ReneUafasah said in Full examples with New_Signal_Slot_Syntax:
Yes, but the example in https://wiki.qt.io/New_Signal_Slot_Syntax is incomplete.
Why
How do you define Sender and Receiver as PointerToMemberFunctions
What does this mean? sender and receiver are pointers to Sender and Receiver class. What else do you need to know here?
-
Yes, but the example in https://wiki.qt.io/New_Signal_Slot_Syntax is incomplete.
How do you define Sender and Receiver as PointerToMemberFunctions
connect(
sender, &Sender::valueChanged,
receiver, &Receiver::updateValue
);assume you want to connect the textChanged signal from a QlineEdit with a QLabel
QLineEdit *lineEdit = new QLineEdit(); //Sender Object/Instance QLabel *label = new QLabel(); //Receiver Object/InstanceQLineEdit has the textChanged signal:
QLineEdit::textChangedQLabel has the slot
setText:
QLabel::setText//connect(senderObject, pointer to signal, receiver, pointer to slot); connect(lineEdit, &QLineEdit::textChanged, label, &QLabel::setText); -
Thank you very much @J-Hilk .
That example helps.