2012-01-29 115 views
1

我有我的应用程序的QML一部分需要知道我在什么状态,currentProfileChanged功能有给我QSystemDeviceInfo::Profile,我想转换为QVaraint,这样的信号在QML可以理解的轮廓为0到7之间的数字,但是这个功能:的QObject连接QSystemDeviceInfo ::简介到的QVariant

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也抱怨不兼容的论点。

回答

0

由于似乎没有更简单的方法,我不得不编写一个函数来转换类型并添加更多的信号插槽,但至少现在可以使用,下面是我的函数(如果需要的话):

#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); 
}; 
0

插槽功能的参数不能与信号中的参数不匹配。您的插槽应指定为..SLOT(changePower(QSystemDeviceInfo::Profile))..

+0

谢谢,但我已尝试但是它母鸡抱怨:[Qt的信息]对象::连接:在C无这样槽QDeclarativeItem_QML_3 :: changePower(QSystemDeviceInfo ::配置文件):/用户/格哈德/ QTProjects/Raker/main.cpp:142 – Gerharddc 2012-01-29 09:44:01

+0

如同Arnold Spence建议 – Neox 2012-01-29 09:53:40

+0

那样,将您的槽声明从'changePower(QVariant(QSystemDeviceInfo :: Profile))'更改为'changePower(QSystemDeviceInfo :: Profile)'在qml中声明一个声明,它看起来像这样:function changePower(power)。所有看起来像这样的其他人都需要QVAriant,然后他们才能工作。 – Gerharddc 2012-01-29 10:03:57