Solved template class that inherits from QObject
-
Hi,
I wrote this class
template <typename t_figure> class drawing : public QObject, public t_figure { Q_OBJECT ...
And when I try to compile it, I get :
mainwindow.o:-1: error: referência indefinida para `drawing<QGraphicsRectItem>::metaObject() const'
Where "referência indefinida" means "undefined reference".
Can I create such a class in Qt?
Thanks
-
@canellas
AFAIK Q_OBJECT macro can't be used in templated classes. -
Indeed. QObjects classes cannot be templated. There are some workarounds for that (example), or you can use Qt modifications (Woboq's moc-less Qt or Coperspice) where it is allowed.
-
Thanks all for your contribution