Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QT : Templated Q_OBJECT class

Is it possible to have a template class, which inherit from QObject (and has Q_OBJECT macro in it's declaration)?

I would like to create something like adapter for slots, which would do something, but the slot can take arbitrary number of arguments (number of arguments depends on the template argument).

I just tried doing it, and got linker errors. I guess gmake or moc is not getting called on this template class. Is there a way to do this? Maybe by explicitly instantiating templates?

like image 861
BЈовић Avatar asked Dec 09 '10 11:12

BЈовић


1 Answers

It is not possible to mix template and Q_OBJECT but if you have a subset of types you can list the slots and signals like this:

    class SignalsSlots : public QObject     {         Q_OBJECT      public:         explicit SignalsSlots(QObject *parent = 0) :             QObject(parent) {}      public slots:         virtual void writeAsync(int value) {}         virtual void writeAsync(float value) {}         virtual void writeAsync(double value) {}         virtual void writeAsync(bool state) {}         virtual void writeAsync(svga::SSlideSwitch::SwitchState state) {}         signals:         void readAsynkPolledChanged(int value);         void readAsynkPolledChanged(float value);         void readAsynkPolledChanged(double value);         void readAsynkPolledChanged(bool state);         void readAsynkPolledChanged(svga::SSlideSwitch::SwitchState state);     }; ... template <class T> class Abstraction : public SignalsSlots {... 
like image 53
Jonas W Avatar answered Oct 01 '22 11:10

Jonas W