Hi,
here is my sample code.
MDM_Example.pro
TARGET = MDM_Example
CONFIG += sailfishapp
CONFIG += link_pkgconfig
PKGCONFIG += sailfishmdm
SOURCES += src/MDM_Example.cpp \
src/baseobject.cpp
DISTFILES += qml/MDM_Example.qml \
qml/cover/CoverPage.qml \
qml/pages/FirstPage.qml \
qml/pages/SecondPage.qml \
rpm/MDM_Example.changes.in \
rpm/MDM_Example.changes.run.in \
rpm/MDM_Example.spec \
rpm/MDM_Example.yaml \
translations/*.ts \
MDM_Example.desktop
SAILFISHAPP_ICONS = 86x86 108x108 128x128 172x172
CONFIG += sailfishapp_i18n
TRANSLATIONS += translations/MDM_Example-de.ts
HEADERS += \
src/baseobject.h
BaseObject.h
#ifndef BASEOBJECT_H
#define BASEOBJECT_H
#include <QObject>
class BaseObject : public QObject
{
Q_OBJECT
public:
explicit BaseObject(QObject *parent = nullptr);
Q_INVOKABLE QString deviceUid() const;
};
#endif // BASEOBJECT_H
BaseObject.cpp
#include "baseobject.h"
#include <mdm-sysinfo.h>
BaseObject::BaseObject(QObject *parent) : QObject(parent)
{
}
QString BaseObject::deviceUid() const
{
return Sailfish::Mdm::SysInfo::deviceUid();
}
MDM_Example.cpp
#ifdef QT_QML_DEBUG
#include <QtQuick>
#endif
#include <sailfishapp.h>
#include "baseobject.h"
int main(int argc, char *argv[])
{
qmlRegisterSingletonType<BaseObject>("org.example",
1,
0,
"BaseObject",
[](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
BaseObject *obj = new BaseObject;
return obj;
});
return SailfishApp::main(argc, argv);
}
Thank you for your help!