- Qt5 C++ GUI Programming Cookbook
- Lee Zhi Eng
- 114字
- 2021-07-02 12:17:57
How it works...
In the good old days, we would typically connect a signal to a slot like this:
connect(
sender, SIGNAL(valueChanged(QString)),
receiver, SLOT(updateValue(QString))
);
However, things have changed slightly since then. In the new syntax, the SIGNAL and SLOT macros are now gone, and you must specify the type of your object, as shown in the following code:
connect(
sender, &Sender::valueChanged,
receiver, &Receiver::updateValue
);
The new syntax also allows you to connect a signal directly to a function instead of QObject:
connect(
sender, &Sender::valueChanged, myFunction
);
Additionally, you can also connect your signal to a lambda expression. We will talk more about this in the Asynchronous programming made easier recipe.