QObject 将 QSystemDeviceInfo::Profile 连接到 QVariant

发布于 2024-12-29 08:06:54 字数 1104 浏览 5 评论 0原文

我的应用程序中有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

御守 2025-01-05 08:06:54

槽函数不能有与信号中的参数不匹配的参数。您的插槽应指定为 ..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))..

┼── 2025-01-05 08:06:54

由于似乎没有更简单的方法,我必须编写一个函数来转换类型并添加更多信号槽,但至少它现在可以工作,如果您需要的话,这是我的函数:

#include <QObject>
#include <QVariant>
#include <QSystemDeviceInfo>
#include <QDebug>

using namespace QtMobility;


class changeVAriant : public QObject
{
    Q_OBJECT

public slots:
    void toVariant(QSystemDeviceInfo::Profile prof)
    {
        emit newVariant(QVariant(prof));
    }
signals:
    void newVariant(QVariant);
};

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:

#include <QObject>
#include <QVariant>
#include <QSystemDeviceInfo>
#include <QDebug>

using namespace QtMobility;


class changeVAriant : public QObject
{
    Q_OBJECT

public slots:
    void toVariant(QSystemDeviceInfo::Profile prof)
    {
        emit newVariant(QVariant(prof));
    }
signals:
    void newVariant(QVariant);
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文