是否有可能有一个从 QObject 继承的模板类(并且在它的声明中有 Q_OBJECT 宏)?
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).
我刚刚尝试这样做,但出现链接器错误.我猜 gmake 或 moc 没有在这个模板类上被调用.有没有办法做到这一点?也许通过显式实例化模板?
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?
混合模板和 Q_OBJECT 是不可能的,但如果你有一个类型的子集,你可以像这样列出插槽和信号:
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
{...
这篇关于QT:模板化 Q_OBJECT 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何在 C++ 中读取和操作 CSV 文件数据?How can I read and manipulate CSV file data in C++?(如何在 C++ 中读取和操作 CSV 文件数据?)
在 C++ 中,为什么我不能像这样编写 for() 循环:In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,为什么我不能像这样编写 for() 循环: for(
OpenMP 如何处理嵌套循环?How does OpenMP handle nested loops?(OpenMP 如何处理嵌套循环?)
在循环 C++ 中重用线程Reusing thread in loop c++(在循环 C++ 中重用线程)
需要精确的线程睡眠.最大 1ms 误差Precise thread sleep needed. Max 1ms error(需要精确的线程睡眠.最大 1ms 误差)
是否需要“do {...} while ()"?环形?Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?环形?)