[Solved] How to use Sailfish MDM in a SailfishApp

Hi Everybody,

I am trying to get some system informations in my app (e.g. Device UID, Device Model, etc.)

During my search I found the SailfishOS MDM API and it seems to provide all information I need.
My problem is I don’t know how to use it at all.

I tried to add as described in the documentation:

CONFIG += link_pkgconfig
PKGCONFIG += sailfishmdm

When I try to access this in my C++ code I get an error during compile:
Error: undefined reference to `SailfishApp::main(int&, char**)’

Is it possible to access this in a SailfishApp instance directly at all?

Or is there an other possibility to get this information in C++?

well, post your code and we can point to your mistake then

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!

Try to omit

CONFIG += link_pkgconfig

in your .pro file. Keep just

PKGCONFIG += sailfishmdm

link_pkgconfig is already added as an effect of adding sailfishapp and there is a nasty bug in qmake that adding link_pkgconfig multiple times makes later changes to PKGCONFIG ineffective or so (IIRC).

3 Likes

Hi martyone,

this solved my problem!

Thank you so much!