Template class not supported by Q_OBJECT
-
@
// -- header file -------------------------------------------
#ifndef MY_CLASS_C_H
#define MY_CLASS_C_H#include <QObject>
template <typename MY_TYPE>
class MY_CLASS_c : public QObject
{
Q_OBJECTpublic:
explicit MY_CLASS_c(QObject *parent = 0);signals:
public slots:
};
#endif // MY_CLASS_C_H
// -- source file --------------------------------------------
#include "my_class_c.h"template <typename MY_TYPE>
MY_CLASS_c <MY_TYPE>::MY_CLASS_c(QObject *parent) :
QObject(parent)
{
}
@@
// -- compiler output ---------------------------------
my_class_c.h:9: Error: Template classes not supported by Q_OBJECT
@can anyone tell me where exactly i am making mistake.???
[Edit] Please "use code wrapping tags ":http://developer.qt.nokia.com/wiki/ForumHelp#e3f82045ad0f480d3fb9e0ac2d58fb01
-
As long as all you need to do is send and receive signals whose parameters are not of the templated type, the solution with a non-template base class, and a template derived class works well.
-
Then, you are out of luck. The only thing you can do then, is wrap the type in a QVariant and emit the signal or define the slot based on the QVariant from the baseclass again. Or, you don't emit the actual value, and let clients call a normal getter method in response to a changed signal instead of sending the value directly. You simply cannot define signals and slots in a template class.