Results 1 to 5 of 5

Thread: Have anyone did template parameter or template class with QT?

  1. #1
    Join Date
    Jun 2010
    Posts
    32
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Have anyone did template parameter or template class with QT?

    What I want to do is create a function called addObject(const T* ob), then other class call this function to add an instance of a class. Is all the classes in QT inherited from QObject by default? If it is the case, maybe I can change my function to be like following: addObject(QObject * ob). But I doubt that.

    If not, how can achieve this? I have tried with addObject(void * ob), seems still couldn't compile, anyone got a clue?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Have anyone did template parameter or template class with QT?

    Explain why you would want to do this? What problem are you trying to solve.

    Many Qt classes are derived from QObject, but not all.

  3. #3
    Join Date
    Apr 2010
    Posts
    34
    Thanks
    1
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Have anyone did template parameter or template class with QT?

    Each pointer can be converted to a void*. If it doesn't work, the problem lies in some other place. But I'm not saying you should use void*.

  4. #4
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Have anyone did template parameter or template class with QT?

    Answer to question is: yes, you can program templates with Qt. (check the link, maybe this is what you are looking for )

    And to add to what ChrisW67 said: the solution is to check the documentation and see what class derive from what, and, as ChrisW67 said: give more details about the problem you are trying to solve, so that we can give better advices.
    Last edited by Zlatomir; 25th June 2010 at 09:07. Reason: corrected a mistake ;)

  5. #5
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Have anyone did template parameter or template class with QT?

    You might want to try the factory design pattern:
    http://cartan.cas.suffolk.edu/oopdoc...e/factory.html

Similar Threads

  1. Template of ingredient class
    By Trok in forum Qt Programming
    Replies: 2
    Last Post: 21st August 2009, 12:27
  2. Replies: 2
    Last Post: 7th July 2008, 08:44
  3. Replies: 1
    Last Post: 15th April 2008, 23:15
  4. Template class
    By steg90 in forum General Programming
    Replies: 15
    Last Post: 12th June 2007, 20:49
  5. template parameter and conversion operator
    By bitChanger in forum General Programming
    Replies: 7
    Last Post: 21st April 2006, 15:36

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.