2014-09-26 1 views
5

Używam C++ 11 składnię połączyć, i pojawia się następujący błąd z tym stwierdzeniem connect:Qt połączyć funkcję - ujednoznacznienie sygnału za pomocą lambdy

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

błąd:

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 można to jakoś przepisać, aby kompilator CAN mógł rozróżnić przeciążoną funkcję?

EDIT:

Od 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.

Jakieś pomysły co dokładnie to makro będzie wyglądać? Albo jak zrobić wyraźny casting?

Odpowiedz

8

trzeba jawnie rzutować wskaźnik przeciążeniem:

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

error C2440: 'inicjowanie': nie można przekonwertować z 'przeciążonej funkcją' na 'void (__cdecl QCompleter :: *) (QModelIndex)' 2 > Żadna z funkcji o tej nazwie nie jest zgodna z typem docelowym –

+0

Musi być (const QModelIndex &), aby w pełni dopasować aktywowany podpis. –

+1

To nauczy mnie nie patrzeć na dokumenty ... – cmannett85