PDA

View Full Version : Have anyone did template parameter or template class with QT?



yyiu002
25th June 2010, 05:26
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?

ChrisW67
25th June 2010, 07:24
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.

Vit Stepanek
25th June 2010, 08:31
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*.

Zlatomir
25th June 2010, 09:03
Answer to question is: yes, you can program templates (http://www.cplusplus.com/doc/tutorial/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.

tbscope
25th June 2010, 09:21
You might want to try the factory design pattern:
http://cartan.cas.suffolk.edu/oopdocbook/opensource/factory.html