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

Matthew Woehlke mwoehlke.floss at gmail.com
Wed Oct 14 20:43:37 CEST 2015


On 2015-10-14 14:26, Bob Hood wrote:
> 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?

There's nothing to be "corrected"; if a signal or slot is overloaded,
you have to specify which one you mean. It's just not something that can
be avoided in the general case¹. Old style does that by giving the full
signature. With new style (and a C++11 compiler), you can use this:

  template<class... Args, class T, class R>
  auto qtOverload(R (T::*m)(Args...)) -> decltype(m)
  { return m; }

...to connect like so:

  connect(mapper, qtOverload<int>(&QSignalMapper::mapped), ...);

(That is, in the <>'s you just need to give the list of parameter types.)

(¹ I seem to recall talk of making QAbstractSocket::error specifically
not overloaded, which would help your exact use case. In general,
however, the only other "solution" is to not ever overload signals or
slots.)

-- 
Matthew




More information about the Interest mailing list