Connecting problem <unresolved overloaded function type>
-
wrote on 30 Aug 2023, 08:26 last edited by
Hi All,
I use Qsignal mapper in a form for buttons. When I try to connect them I have
error: no matching function for call to 'QPushButton::connect(QPushButton*&, void (QAbstractButton::)(), QSignalMapper&, <unresolved overloaded function type>)'
error: no matching function for call to 'QPushButton::connect(QPushButton*&, void (QAbstractButton::)(), QSignalMapper&, <unresolved overloaded function type>)'
49 | buton->connect(buton, &QPushButton::pressed ,TheMapper, &QSignalMapper::map);
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^QList<QPushButton *> widgetlist = this->findChildren<QPushButton *>(); foreach (QPushButton *buton, widgetlist) { if ((buton->toolTipDuration() > 0) && (buton->toolTipDuration() < 5000)) { //buton->connect(buton,SIGNAL(pressed()),TheMapper,SLOT(map())); buton->connect(buton, &QPushButton::pressed ,TheMapper, &QSignalMapper::map); TheMapper->setMapping(buton,buton->toolTipDuration()); ObjectMap->insert(buton->toolTipDuration(),buton); itemslist->insert(buton->toolTipDuration(),new vitem); connect(qobject_cast<vitem*>(itemslist->value(buton->toolTipDuration())),&vitem::boolvaluechanged, buton ,&QPushButton::setFlat); //qDebug()<< buton->objectName(); }
At Qt5 the commented connecting was working.. Any Solution?
-
@zeroptr
Did you click on the https://doc.qt.io/qt-6/qoverload-proxy.html#qOverload link @sierdzio gave you? It shows you how to useqOverload()
to specify which overload of a method which has multiple signatures you want to use.There are two possible slots:
void QSignalMapper::map()
void QSignalMapper::map(QObject *sender)
You need to tell C++ which one to use.wrote on 31 Aug 2023, 07:20 last edited by zeroptrbuton->connect(buton, &QPushButton::pressed ,TheMapper,qOverload<>(&QSignalMapper::map));
solved
-
Hi All,
I use Qsignal mapper in a form for buttons. When I try to connect them I have
error: no matching function for call to 'QPushButton::connect(QPushButton*&, void (QAbstractButton::)(), QSignalMapper&, <unresolved overloaded function type>)'
error: no matching function for call to 'QPushButton::connect(QPushButton*&, void (QAbstractButton::)(), QSignalMapper&, <unresolved overloaded function type>)'
49 | buton->connect(buton, &QPushButton::pressed ,TheMapper, &QSignalMapper::map);
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^QList<QPushButton *> widgetlist = this->findChildren<QPushButton *>(); foreach (QPushButton *buton, widgetlist) { if ((buton->toolTipDuration() > 0) && (buton->toolTipDuration() < 5000)) { //buton->connect(buton,SIGNAL(pressed()),TheMapper,SLOT(map())); buton->connect(buton, &QPushButton::pressed ,TheMapper, &QSignalMapper::map); TheMapper->setMapping(buton,buton->toolTipDuration()); ObjectMap->insert(buton->toolTipDuration(),buton); itemslist->insert(buton->toolTipDuration(),new vitem); connect(qobject_cast<vitem*>(itemslist->value(buton->toolTipDuration())),&vitem::boolvaluechanged, buton ,&QPushButton::setFlat); //qDebug()<< buton->objectName(); }
At Qt5 the commented connecting was working.. Any Solution?
-
-
The functor-based connection syntax requires providing a pointer to signal and slot in
connect
call. But if you have overloaded functions, for example:public slots: void doSomething(int i); void doSomething(QString i);
then functor syntax is ambiguous:
&YouClass::doSomething
might mean the integer or QString variant of the method. WithqOverload
you can specify exactly which method you mean to connect to. -
wrote on 30 Aug 2023, 09:02 last edited by
@zeroptr
Did you click on the https://doc.qt.io/qt-6/qoverload-proxy.html#qOverload link @sierdzio gave you? It shows you how to useqOverload()
to specify which overload of a method which has multiple signatures you want to use.There are two possible slots:
void QSignalMapper::map()
void QSignalMapper::map(QObject *sender)
You need to tell C++ which one to use. -
@zeroptr
Did you click on the https://doc.qt.io/qt-6/qoverload-proxy.html#qOverload link @sierdzio gave you? It shows you how to useqOverload()
to specify which overload of a method which has multiple signatures you want to use.There are two possible slots:
void QSignalMapper::map()
void QSignalMapper::map(QObject *sender)
You need to tell C++ which one to use.wrote on 31 Aug 2023, 07:20 last edited by zeroptrbuton->connect(buton, &QPushButton::pressed ,TheMapper,qOverload<>(&QSignalMapper::map));
solved
-
-
buton->connect(buton, &QPushButton::pressed ,TheMapper,qOverload<>(&QSignalMapper::map));
solved
wrote on 31 Aug 2023, 07:47 last edited by JonB@zeroptr
[EDIT: This reply posted before you latest "solved" post.]Now I'm not sure what you're asking.
QOverload(&QSignalMapper::map)
simply does not exist, we never saidQOverload(...)
.I see that https://forum.qt.io/topic/93385/how-to-use-qoverload/4 says
qOverload<>
may not work on some Windows compilers, so let's useQOverload<>::of()
.For your original I would expect
buton->connect(buton, &QPushButton::pressed ,TheMapper, QOverload<>::of(&QSignalMapper::map));
That would pick the overload with no parameters, i.e.
void QSignalMapper::map()
. TheQPushButton::pressed()
signal does not pass aQObject *
, so you can't callvoid QSignalMapper::map(QObject *sender)
. -
wrote on 31 Aug 2023, 07:51 last edited by
Hi, also consider switching to using lambdas instead of QSignalMapper (which seems to be on it's way out of Qt) say like this:
QList<QPushButton *> widgetlist = this->findChildren<QPushButton *>(); foreach (QPushButton *buton, widgetlist) { if ((buton->toolTipDuration() > 0) && (buton->toolTipDuration() < 5000)) { buton->connect(buton, &QPushButton::pressed, this, [this, buton] { buton->setFlat(true); } ); //qDebug()<< buton->objectName(); }
Note: haven't tested this :-)
-
Hi, also consider switching to using lambdas instead of QSignalMapper (which seems to be on it's way out of Qt) say like this:
QList<QPushButton *> widgetlist = this->findChildren<QPushButton *>(); foreach (QPushButton *buton, widgetlist) { if ((buton->toolTipDuration() > 0) && (buton->toolTipDuration() < 5000)) { buton->connect(buton, &QPushButton::pressed, this, [this, buton] { buton->setFlat(true); } ); //qDebug()<< buton->objectName(); }
Note: haven't tested this :-)
wrote on 31 Aug 2023, 08:11 last edited by JonB@hskoglund
You are missing parentheses to help the OP get the syntax right:[this, buton] () { buton->setFlat(true); }
Here you could pass just
buton
in[...]
context,this
is not used. Though no harm done, just so the OP knows.@zeroptr
Absolutely do move over fromQSignalMapper
to lambdas, much preferable. -
@hskoglund
You are missing parentheses to help the OP get the syntax right:[this, buton] () { buton->setFlat(true); }
Here you could pass just
buton
in[...]
context,this
is not used. Though no harm done, just so the OP knows.@zeroptr
Absolutely do move over fromQSignalMapper
to lambdas, much preferable. -
wrote on 31 Aug 2023, 08:46 last edited by
@hskoglund said in Connecting problem <unresolved overloaded function type>:
the parentheses are optional
Wow, really? I never knew that!
1/11