I do not understand this syntax, which does not work
-
Hello,
in the doc here is the syntax@connect (sender, & Sender :: valueChanged,
receiver, Receiver & updateValue ::);@But it does not work ..
for example if I wrote this:@QObject :: connect (m_actionQuitter, and QAction :: triggered, creerMenu ());@
is not it?
it does not work :/@FenPrincipale.cpp:72: erreur : C2664: 'QMetaObject::Connection QObject::connect(const QObject *,const char *,const char ,Qt::ConnectionType) const' : cannot convert parameter 2 from 'void (__thiscall QAction:: )(bool)' to 'const char *'
There is no context in which this conversion is possible@ -
Try this:
@QObject::connect(m_actionQuitter, &QAction::triggered, m_Receiver, &ReceiverObject::creerMenu);@Replace m_Receiver with class that should receive the signals and ReceiverObject with class type that m_Receiver is.
Also make sure that parameters are the same in both methods.
-
Hello,
Have a look at C++ syntax for function pointers (especially pointers-to-member-functions).
For the new version of QObject::connect() with 4 arguments, the arguments are:
Pointer to the object that emits the signal
Pointer to the member-function that acts as the signal
Pointer to the object that receives the signal
Pointer to the member-function that acts as the slot
Your example uses a version with 3 arguments, which are:
Pointer to the object that emits the signal
Pointer to the member-function that acts as the signal
Pointer to the non-member-function to be invoked
[quote author="nostrora" date="1356603974"]in the doc here is the syntax
@connect (sender, & Sender :: valueChanged,
receiver, Receiver & updateValue ::);@
[/quote]Be careful -- You have an extra "::" at the end[quote author="nostrora" date="1356603974"]
@QObject :: connect (m_actionQuitter, and QAction :: triggered, creerMenu ());@
[/quote]Don't write "and". In C++, "&" has special meanings.If creerMenu() doesn't belong to a class, there are two correct ways to write it:
@
QObject::connect(m_actionQuitter, &QAction::triggered, creerMenu);QObject::connect(m_actionQuitter, &QAction::triggered, &creerMenu);
@But, if creerMenu() belongs to a class, use Jake007's version.