我有这样的课:
#include <QObject>
namespace taservices
{
class ProcessHandle : public QObject
{
Q_OBJECT
public:
ProcessHandle(const void* const processContextPointer, const QString& process_id = "", QObject *parent = 0);
ProcessHandle();
signals:
void progress(const ProcessHandle* const self, const int value);
private:
static void registerAsMetaType();
}
我有一个信号:
void progress(const ProcessHandle* const self, const int value);
我想通过 QueuedConnedtion 连接它。我不断收到此消息:
QObject::connect: Cannot queue arguments of type 'ProcessHandle*const'
(Make sure 'ProcessHandle*const' is registered using qRegisterMetaType().)
我在声明之后像这样注册我的班级:
Q_DECLARE_METATYPE(taservices::ProcessHandle*);
我还添加了这个从构造函数调用的静态方法:
void ProcessHandle::registerAsMetaType()
{
static bool called = false;
if(!called) {
called = true;
qRegisterMetaType<ProcessHandle*>("taservices::ProcessHandle*");
}
}
我也尝试注册const
指针:
qRegisterMetaType<ProcessHandle*const>("taservices::ProcessHandle*const");
它会导致以下错误:
error C2440: 'return' : cannot convert from 'taservices::ProcessHandle *const *' to 'void *'
那么如何让我的班级使用排队连接?