[Qt-interest] Virtual signals in base class?

Rohan McGovern rohan.mcgovern at nokia.com
Thu Sep 9 10:02:55 CEST 2010


Robert Caldecott said:
> Whilst reviewing some Qt C++ code I came across this:
> 
> class Foo
> {
>   Q_OBJECT
> 
> signals:
>   virtual void someSignal(const QString& str, int n)
>   {
>     Q_UNUSED(str);
>     Q_UNUSED(n);
>   }
>   ...
> };
> 
> Now, Qt signals cannot have a body so I'm surprised this even compiles
> (perhaps because the body is effectively empty). I also don't see the
> point of making a signal virtual (as it can't have a body so how can
> it be overridden?)
> 

The code is wrong, but it could possibly be compiled if moc was not run
over this class, or if the code generated by moc wasn't linked in.
-- 
Rohan McGovern
QA Engineer
Qt Development Frameworks, Nokia



More information about the Qt-interest-old mailing list