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.
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);
};