QObject 将 QSystemDeviceInfo::Profile 连接到 QVariant
我的应用程序中有一个 QML 部分需要知道我所处的状态。currentProfileChanged
函数有一个信号,为我提供一个我想要的 QSystemDeviceInfo::Profile
转换为 QVaraint
以便 QML 可以将配置文件理解为 0 到 7 之间的数字,但是这个函数:
QObject::connect(deviceInfo,
SIGNAL(currentProfileChanged(QSystemDeviceInfo::Profile)),
rootObject,
SLOT(changePower(QVariant(QSystemDeviceInfo::Profile))));
给出了这个奇怪的错误:
[Qt Message] Object::connect: No such slot
QDeclarativeItem_QML_3::changePower(QVariant(QSystemDeviceInfo::Profile))
in C:/Users/Gerhard/QTProjects/Raker/main.cpp:142
我在这里做错了什么?
如果我尝试这样做:
QObject::connect(deviceInfo,
SIGNAL(currentProfileChanged(QSystemDeviceInfo::Profile)),
rootObject,
SLOT(changePower(QVariant(QSystemDeviceInfo::Profile))));
它会这样说:
[Qt Message] Object::connect: No such slot
QDeclarativeItem_QML_3::changePower(QSystemDeviceInfo::Profile)
in C:/Users/Gerhard/QTProjects/Raker/main.cpp:142
如果我将其中任何一个或两个更改为 QVariant,它也会抱怨不兼容的参数。
I have a QML part of my application that needs to know what state I'm in. The currentProfileChanged
function has a signal giving me a QSystemDeviceInfo::Profile
that I want to convert to a QVaraint
so that the QML can understand the profile as a number between 0 and 7, but this function:
QObject::connect(deviceInfo,
SIGNAL(currentProfileChanged(QSystemDeviceInfo::Profile)),
rootObject,
SLOT(changePower(QVariant(QSystemDeviceInfo::Profile))));
Gives this strange error:
[Qt Message] Object::connect: No such slot
QDeclarativeItem_QML_3::changePower(QVariant(QSystemDeviceInfo::Profile))
in C:/Users/Gerhard/QTProjects/Raker/main.cpp:142
What I am doing wrong here?
If I try this:
QObject::connect(deviceInfo,
SIGNAL(currentProfileChanged(QSystemDeviceInfo::Profile)),
rootObject,
SLOT(changePower(QVariant(QSystemDeviceInfo::Profile))));
It says this:
[Qt Message] Object::connect: No such slot
QDeclarativeItem_QML_3::changePower(QSystemDeviceInfo::Profile)
in C:/Users/Gerhard/QTProjects/Raker/main.cpp:142
If I change any or both to just QVariant it also complains about incompatible arguments.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
槽函数不能有与信号中的参数不匹配的参数。您的插槽应指定为
..SLOT(changePower(QSystemDeviceInfo::Profile))..
The slot function cannot have a parameter that doesn't match a parameter in the signal. Your slot should be specified as
..SLOT(changePower(QSystemDeviceInfo::Profile))..
由于似乎没有更简单的方法,我必须编写一个函数来转换类型并添加更多信号槽,但至少它现在可以工作,如果您需要的话,这是我的函数:
As there appears to be no easier way I had to write a function to convert the types and add some more signal slots but at least it works now, here's my function if you want it: