2014-09-26 11 views
5

Ich bin mit der C++ 11 connect Syntax, und die folgenden Fehler mit dieser Connect-Anweisung:Qt verbinden Funktion - Begriffsklärung Signal lambdas mit

connect(fileSystemCompleter, &QCompleter::activated, [&] (QModelIndex index) 
{ 
    fileSystemPathEdit->setFocus(Qt::PopupFocusReason); 
}); 

Fehler:

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 

Ist Kann man das irgendwie umschreiben, damit der Compiler die überladene Funktion disambiguieren kann?

EDIT:

Von Qt-Projekt ...

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.

Irgendwelche Ideen, was genau dieses Makro würde so aussehen? Oder wie man das explizite Casting macht?

Antwort

8

Sie haben zu werfen explizit die Überlastung Zeiger:

void (QCompleter::* activatedOverloadPtr)(const QModelIndex&) = &QCompleter::activated; 
connect(fileSystemCompleter, activatedOverloadPtr, [&] (QModelIndex index) 
{ 
    fileSystemPathEdit->setFocus(Qt::PopupFocusReason); 
}); 
+0

Fehler C2440: 'initialisieren': kann nicht von 'überlastet-Funktion' auf 'void (__cdecl QCompleter :: *) (QModelIndex)' konvertieren 2 > Keine der Funktionen mit diesem Namen im Gültigkeitsbereich stimmt mit dem Zieltyp –

+0

Muss überein (const QModelIndex &), um die aktivierte Signatur vollständig zu finden. –

+1

Das bringt mir bei, die Dokumente nicht zu betrachten ... – cmannett85

Verwandte Themen