Results 1 to 3 of 3

Thread: signal/slots in template classes

  1. #1

    Default signal/slots in template classes

    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:

    Qt Code:
    1. template <class T>
    2. class ColladaReference :
    3. public QObject
    4. {
    5. Q_OBJECT
    6. public:
    7. ColladaReference(){};
    8. ColladaReference(T *ref){reference = ref;}
    9. ~ColladaReference(){};
    10.  
    11. void deleteReference();
    12.  
    13. private:
    14. T *reference;
    15. };
    16. ==========
    17. template <class T>
    18. class ColladaRepresentation :
    19. public QObject
    20. {
    21. Q_OBJECT
    22. public:
    23. ColladaRepresentation(){representation = NULL;} // constructor
    24. ColladaRepresentation(T *rep){representation = rep;} // constructor with collada ptr
    25.  
    26. void setRepresentation(T *rep){representation = rep;}
    27. public slots:
    28. void deleteRepresentation();
    29. signals:
    30. void representationDeleted(){};
    31. private:
    32. T * representation;
    33. };
    34. ====================
    35. typedef ColladaRepresentation<domGeometry> GeometryRepresentation;
    36. typedef ColladaReference<domInstance_geometry> GeometryReference;
    37. ====================
    38. GeometryReference *geometryReference = new GeometryReference(instanceGeometry);
    39. GeometryRepresentation *geometryRepresentation = new GeometryRepresentation(geometryNode[k]);
    40. connect(geometryRepresentation, SIGNAL(representationDeleted()), geometryReference, SLOT(deleteReference()));
    41. =================
    To copy to clipboard, switch view to plain text mode 
    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

  2. #2
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: signal/slots in template classes

    Have you had a look at this article? http://doc.trolltech.com/qq/qq15-academic.html

  3. #3
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: signal/slots in template classes

    No, it's not generally possible to use signal/slots in template classes. That's because MOC/UI are pre-processors but the actual classes don't get generated until compile time. This is the one disadvantage of signal/slots I've run across.

Similar Threads

  1. QtTest: Unittesting in several classes
    By Jojo in forum Qt Programming
    Replies: 2
    Last Post: 25th August 2009, 12:38
  2. problem using template
    By mickey in forum General Programming
    Replies: 6
    Last Post: 18th November 2006, 15:57
  3. How to search a string in xml file with Qt Dom classes
    By doganay44 in forum Qt Programming
    Replies: 2
    Last Post: 5th October 2006, 20:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.