[Qt-interest] Making a template class a Q_OBJECT

John Clayton johnclayton72 at gmail.com
Wed Dec 16 00:09:52 CET 2009


Hi All

I'm wondering how I can make my template class a Q_OBJECT type.

I've got a template, defined like this:

template<typename T = QGraphicsObject>
class PreviewGraphicsItem : public T, // must be some kind of QObject
			public PreviewBase,
			public ControlPoint::Delegate
{

// Q_OBJECT
// the above line will cause compiler errors - wonder what the work- 
around is?

public:
	// magic stuff goes here...
};


What I really want to do is put a Q_OBJECT decl just above the public:  
access specifier, but that doesn't work (compiler complains bitterly).

The class defines common functionality for an object that sits in a  
preview window (within a graphics scene).  It will always have a  
template parameter that is derived from QObject.

The reason I want to put the Q_OBJECT macro in there, is because I'd  
like to implement Q_PROPERTY statements at this level in the hierarchy.

Your ideas are appreciated,

Thanks
--
John Clayton





More information about the Qt-interest-old mailing list