c++ - QObject::connect() 带有枚举参数

标签 c++ qt

我正在尝试将 QObject::connect() 与枚举参数一起使用。我收到这条消息...

QObject::connect: Incompatible sender/receiver arguments
        Calendar::calendarExceptionThrown(Calendar*,ExceptionType)
   --> CalendarDBView::handleCalendarException(Calendar*,Calendar::ExceptionType)

连接代码是:

 connect(cal, SIGNAL(calendarExceptionThrown(Calendar*,ExceptionType)),
         this, SLOT(handleCalendarException(Calendar*,Calendar::ExceptionType)));

根据我的阅读,我认为我需要将其添加到 Calendar 的类定义中:

Q_ENUMS(ExceptionType)

我将此添加到 main.cpp:

qRegisterMetaType<Calendar::ExceptionType>("ExceptionType");

我仍然收到警告消息。 This related thread没有解决我的问题。我做错了什么?

最佳答案

我相信如果您只是在连接的 SIGNAL 部分将 ExceptionType 更改为 Calendar::ExceptionType,它就会解决问题。 moc 期望 SIGNAL 和 SLOT 的字符串匹配。

关于c++ - QObject::connect() 带有枚举参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9179584/

相关文章:

c++ - 对结构成员的临时绑定(bind)引用

qt - QT : qml quick? 中的未知模块

c++ - 在 qmlRegisterSingletonType 中使用非静态方法

C++ - Qt Creator 中的 Poco 库

c++ - Tensorflow 和 Bazel C++

c++ - BlackBerry 10 Cascades - 如何导航到另一个 CPP 类

c++ - C++在什么情况下会调用继承类的构造函数失败?

c++ - 在 stringstream 中使用固定和设置精度时 C++ 的舍入误差

C++ 我想将两个字符串写入管道,两者之间有一个小的延迟

c++ - 修改嵌套lambda中捕获的参数 : gcc vs clang?