connect() does not take signalMapper as slot
-
Hi, I'm using almost the same code from QSignalMapper document
signalMapper = new QSignalMapper(this); QPushButton *button = new QPushButton("test"); connect(button, &QPushButton::clicked, signalMapper, &QSignalMapper::map);However I got error:
configdialog.cpp:89:5: No matching member function for call to 'connect' qobject.h:222:36: candidate function not viable: no known conversion from 'void (QAbstractButton::*)(bool)' to 'const char *' for 2nd argument qobject.h:225:36: candidate function not viable: no known conversion from 'void (QAbstractButton::*)(bool)' to 'const QMetaMethod' for 2nd argument qobject.h:481:41: candidate function not viable: no known conversion from 'void (QAbstractButton::*)(bool)' to 'const char *' for 2nd argument qobject.h:242:43: candidate template ignored: couldn't infer template argument 'Func2' qobject.h:283:13: candidate template ignored: couldn't infer template argument 'Func2' qobject.h:322:13: candidate template ignored: couldn't infer template argument 'Func2' qobject.h:274:13: candidate function template not viable: requires 3 arguments, but 4 were provided qobject.h:314:13: candidate function template not viable: requires 3 arguments, but 4 were providedMy other connect() works all fine except QSignalMapper. Am I not using it correctly? Thanks.
-
Hi, I'm using almost the same code from QSignalMapper document
signalMapper = new QSignalMapper(this); QPushButton *button = new QPushButton("test"); connect(button, &QPushButton::clicked, signalMapper, &QSignalMapper::map);However I got error:
configdialog.cpp:89:5: No matching member function for call to 'connect' qobject.h:222:36: candidate function not viable: no known conversion from 'void (QAbstractButton::*)(bool)' to 'const char *' for 2nd argument qobject.h:225:36: candidate function not viable: no known conversion from 'void (QAbstractButton::*)(bool)' to 'const QMetaMethod' for 2nd argument qobject.h:481:41: candidate function not viable: no known conversion from 'void (QAbstractButton::*)(bool)' to 'const char *' for 2nd argument qobject.h:242:43: candidate template ignored: couldn't infer template argument 'Func2' qobject.h:283:13: candidate template ignored: couldn't infer template argument 'Func2' qobject.h:322:13: candidate template ignored: couldn't infer template argument 'Func2' qobject.h:274:13: candidate function template not viable: requires 3 arguments, but 4 were provided qobject.h:314:13: candidate function template not viable: requires 3 arguments, but 4 were providedMy other connect() works all fine except QSignalMapper. Am I not using it correctly? Thanks.
@dalishi
I think: We are dealing with overloads of QSignaller::map() method. Doc example may not be up-to-date? Try:QOverload<>::of(&QSignalMapper::map)Does that fix?
See https://stackoverflow.com/questions/68552698/connecting-qsignalmapper-qt-5-15-2. -
JonB beat me to it. :)
connect(button, &QPushButton::clicked, signalMapper, qOverload<>(&QSignalMapper::map) );
-
JonB beat me to it. :)
connect(button, &QPushButton::clicked, signalMapper, qOverload<>(&QSignalMapper::map) );
-
@dalishi
I think: We are dealing with overloads of QSignaller::map() method. Doc example may not be up-to-date? Try:QOverload<>::of(&QSignalMapper::map)Does that fix?
See https://stackoverflow.com/questions/68552698/connecting-qsignalmapper-qt-5-15-2. -
JonB beat me to it. :)
connect(button, &QPushButton::clicked, signalMapper, qOverload<>(&QSignalMapper::map) );
@mrjj it seems we need ::of here as in @JonB 's post. Otherwise we get the error:
configdialog.cpp:91:71: Address of overloaded function 'map' does not match required type 'QOverload<>' qsignalmapper.h:85:10: candidate function qsignalmapper.h:86:10: candidate functionand it is QOverload<> not qOverload<> tho, haha, thanks.
-