I'm using the c++11 connect syntax, and get the following error with this connect statement:
connect(fileSystemCompleter, &QCompleter::activated, [&] (QModelIndex index)
{
fileSystemPathEdit->setFocus(Qt::PopupFocusReason);
});
error:
error C2664: 'QMetaObject::Connection QObject::connect(const QObject *,const char *,const char *,Qt::ConnectionType) const' : cannot convert parameter 2 from 'overloaded-function' to 'const char *'
Context does not allow for disambiguation of overloaded function
Is it possible to rewrite this somehow so that the compiler CAN disambiguate the overloaded function?
EDIT:
From Qt Project...
Overload
As you might see in the example, connecting to QAbstractSocket::error is not really beautiful since error has an overload, and taking the address of an overloaded function requires explicit casting.
Some macro could help (with c++11 or typeof extensions)
The best thing is probably to recommend not to overload signals or slots …
… but we have been adding overloads in past minor releases of Qt because taking the address of a function was not a use case we support. But now this would be impossible without breaking the source compatibility.
Any ideas what exactly this macro would look like? Or how to do the explicit casting?
You have to explicitly cast the overload pointer:
void (QCompleter::* activatedOverloadPtr)(const QModelIndex&) = &QCompleter::activated;
connect(fileSystemCompleter, activatedOverloadPtr, [&] (QModelIndex index)
{
fileSystemPathEdit->setFocus(Qt::PopupFocusReason);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With