Search code examples
qttemplatesqt-designer

Inheriting from QWidget and make class a Template


I hope this is not a silly question, but I am very inexperienced in templating, and this problem goes over my head. I work on a project that relies heavily on QT Designer for GUI Design, and I want to make available a special QWidget subclass which allows to abstract interaction with a complicated service mechanism. This widget needs class specific Information, to resolve the services. The coding itself is done in Visual Studio 2008.

So what I want to create is a templated QWidget Subclass. With my limited knowledge, I tried slapping the usual template statement in front of the class:

template <class T>
class QmitkMyWidget :public QWidget

unsuprisingly, this does not work that easily. The generated moc classes act up.

error PRJ0019: A tool returned an error code from "Generating Qmitk/moc_QmitkMyWidget.cxx"

Which seems kind of logical to me since I "didn't tell them what to do". I figure I have to specify templating inside of QT Designer, but i really do not no how, and unfortunaley searching finds tons of result for code templates in QT Designer, but none about the generic programming concept. I'd really appreciate any hint && || helpful sources/articles. Thanks for your time!

Edit: Silly typo in the first code =/


Solution

  • I have confirmed that this is impossible. Source: Limitations mof the moc concept

    The gist is, that mocs are preprocessed, but templates are only translated into actual code on compile time.

    Edit: I may add that instead of making the class itself templated, I am now only templating the public functions, which works quite well so far, though it of course requires to consumer to type out the declaration everytime he calls the function.