killkolor
6th December 2006, 17:54
hi!
i have a couple of template classes and let them inherit from QObject to use the signal/slot observer pattern. at compile-time though i get a whole lot of linker errors. is it possible to use qt's signal/slot mechanism in template classes? if not, are there alternatives?
i'll give some samples out of my code and one of the linker errors to make things a bit clearer:
template <class T>
class ColladaReference :
public QObject
{
Q_OBJECT
public:
ColladaReference(){};
ColladaReference(T *ref){reference = ref;}
~ColladaReference(){};
void deleteReference();
private:
T *reference;
};
==========
template <class T>
class ColladaRepresentation :
public QObject
{
Q_OBJECT
public:
ColladaRepresentation(){representation = NULL;} // constructor
ColladaRepresentation(T *rep){representation = rep;} // constructor with collada ptr
void setRepresentation(T *rep){representation = rep;}
public slots:
void deleteRepresentation();
signals:
void representationDeleted(){};
private:
T * representation;
};
====================
typedef ColladaRepresentation<domGeometry> GeometryRepresentation;
typedef ColladaReference<domInstance_geometry> GeometryReference;
====================
GeometryReference *geometryReference = new GeometryReference(instanceGeometry);
GeometryRepresentation *geometryRepresentation = new GeometryRepresentation(geometryNode[k]);
connect(geometryRepresentation, SIGNAL(representationDeleted()), geometryReference, SLOT(deleteReference()));
=================
Error 3 error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall ColladaReference<class domInstance_geometry>::metaObject(void)const " (?metaObject@?$ColladaReference@VdomInstance_geome try@@@@UBEPBUQMetaObject@@XZ) colladaLoader.obj
i have a couple of template classes and let them inherit from QObject to use the signal/slot observer pattern. at compile-time though i get a whole lot of linker errors. is it possible to use qt's signal/slot mechanism in template classes? if not, are there alternatives?
i'll give some samples out of my code and one of the linker errors to make things a bit clearer:
template <class T>
class ColladaReference :
public QObject
{
Q_OBJECT
public:
ColladaReference(){};
ColladaReference(T *ref){reference = ref;}
~ColladaReference(){};
void deleteReference();
private:
T *reference;
};
==========
template <class T>
class ColladaRepresentation :
public QObject
{
Q_OBJECT
public:
ColladaRepresentation(){representation = NULL;} // constructor
ColladaRepresentation(T *rep){representation = rep;} // constructor with collada ptr
void setRepresentation(T *rep){representation = rep;}
public slots:
void deleteRepresentation();
signals:
void representationDeleted(){};
private:
T * representation;
};
====================
typedef ColladaRepresentation<domGeometry> GeometryRepresentation;
typedef ColladaReference<domInstance_geometry> GeometryReference;
====================
GeometryReference *geometryReference = new GeometryReference(instanceGeometry);
GeometryRepresentation *geometryRepresentation = new GeometryRepresentation(geometryNode[k]);
connect(geometryRepresentation, SIGNAL(representationDeleted()), geometryReference, SLOT(deleteReference()));
=================
Error 3 error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall ColladaReference<class domInstance_geometry>::metaObject(void)const " (?metaObject@?$ColladaReference@VdomInstance_geome try@@@@UBEPBUQMetaObject@@XZ) colladaLoader.obj