Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, December 2006
qmake & moc (Q_OBJECT in .h vs .cpp)


Message 1 in thread

Hi,
I'm using subclassed widgets togther with qmake. My subclasses use the
Q_OBJECT macro.

What I've noticed is that if I define my classes using Q_OBJECT in a
.h file then I don't need to consider moc at all - qmake handles it
transparently. However, if I define my classes using Q_OBJECT in a
.cpp file, then I get vTable related linker errors unless I #include
the generated .moc file in my source...

ie. main.cpp uses Q_OBJECT => main.cpp needs to #include "main.moc".

Is this qmake difference between Q_OBJECT usage in .h vs .cpp files
normal? Is there anything that I should be doing to make it work
transparently in the "Q_OBJECT used in .cpp file" case without
#including the generated .moc file?

Thanks!
Ben

--
 [ signature omitted ] 

Message 2 in thread

On 01.12.06 13:02:52, Ben Bridgwater wrote:
> Is this qmake difference between Q_OBJECT usage in .h vs .cpp files
> normal?

Yes, qmake only checks files mentioned in HEADERS for class
declarations and runs moc on them.

> Is there anything that I should be doing to make it work
> transparently in the "Q_OBJECT used in .cpp file" case without
> #including the generated .moc file?

You could try adding your .cpp files to HEADERS.

But I don't quite understand why you put class declarations of
non-internal classes into .cpp files. This gets messy ;)

Andreas

-- 
 [ signature omitted ] 

Message 3 in thread

> You could try adding your .cpp files to HEADERS.

Thanks, Andreas.

> But I don't quite understand why you put class declarations of
> non-internal classes into .cpp files. This gets messy ;)

Hey, I was writing Modula-2 back in 1980.... but sometimes all a
simple test app needs is just a main.cpp! ;-)

Ben

--
 [ signature omitted ]