[Qt-interest] Weird qobject_cast issue with QFutureWatcher...

Thiago Macieira thiago.macieira at trolltech.com
Fri Jul 24 09:12:24 CEST 2009


Gary Coulbourne wrote:
>I'm having a devil of a time with qobject_cast on the sender() method in
> a slot when the sender is QFutureWatcher.  I've created a trivial test
> case that duplicates it, and have copied it into this email.  When it
> compiles, it ends up with "void value not ignored as it ought to be" as
> the error on the line with the qobject_cast.  I've searched the mailing
> lists, and they suggested that a missing Q_OBJECT macro could be the
> trouble, but no dice.

The reason is that it's not expected to work. But you wouldn't have known 
unless you tried and/or asked.

qobject_cast requires the class that you're trying to cast to not only 
derive from QObject, but also have its own Q_OBJECT macro.

QFutureWatcher<T> doesn't have it. It derives from QObject (indirectly) 
but doesn't have Q_OBJECT, since moc can't handle templates. That means 
static_cast will work, however.

-- 
Thiago Macieira - thiago.macieira (AT) nokia.com
  Senior Product Manager - Nokia, Qt Software
      Sandakerveien 116, NO-0402 Oslo, Norway
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090724/afd39bcd/attachment.bin 


More information about the Qt-interest-old mailing list