[Interest] Odd new-style connect()/disconnect() error with Qt 5.5.0

André Somers andre at familiesomers.nl
Thu Oct 15 09:11:55 CEST 2015


Op 14-10-2015 om 20:26 schreef Bob Hood:
> On 10/14/2015 12:04 PM, Elvis Stansvik wrote:
>> I believe it is because QAbstractSocket::error is an overloaded
>> function, so it is ambiguous in your connect/disconnect calls. It
>> needs to be statically casted :/ See e.g:
>>
>>      https://wiki.qt.io/New_Signal_Slot_Syntax#Overload
>>
> Ah, that would be the problem, I guess.  Thanks, Elvis.  :)
>
> That would also explain why the old-style connects work.I can go back to that
> for this particular case.  Assuming this is addressable, does anybody know if
> there are there plans to correct this new-style issue in a future release, or
> should I just plan on using old-style connects in these instances?

I am using this little helper for those cases:

//tricktomakeconnectingwithQt5-styleconnectstooverloadedsignals
template<typename...Args>structSELECT{

template<typenameC,typenameR>

staticconstexprautoOVERLOAD_OF(R(C::*pmf)(Args...))->decltype(pmf){

returnpmf;

}

};

I found it 
http://stackoverflow.com/questions/16794695/qt5-overloaded-signals-and-slots

It allows you to connect like this for your case:

connect(stream.data(), 
SELECT<QAbstractSocket::SocketError>::OVERLOAD_OF<QTcpSocket::error>,
         this,  &TCPChannel::slot_socket_error);

I find that a lot more readable than the manual cast.

André
//


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20151015/d27d4f86/attachment.html>


More information about the Interest mailing list