Can we use the qml-webos-bridge plugin in the Built-in Native Apps

Hello,

I'm following the guideline Developing Built-in Native Apps. But now, I want to render things using QML code rather than OpenGL.

The problem occurs when I try to get the system time using the following QML code:

Service {
    id: systemService
    appId: "com.example.app.nativeqt"

    function getTime() {
        call("luna://com.webos.service.systemservice","/clock/getTime","{}")
    }

    onResponse: pmLog.info("GETTIME", {"utc": JSON.parse(payload).utc})
    onError: pmLog.error("GETTIME", {"error": JSON.parse(payload)})
}

Here is the errors:

May 20 20:56:20 qemux86-64 nativeqt[1408]: [pmlog] NATIVE_QML_APP com.example.app.nativeqt {} (null), Deprecated: the property Window.appId will become read-only. Use QGuiApplication.applicationName instead.

May 20 20:56:20 qemux86-64 nativeqt[1408]: [pmlog] NATIVE_QML_APP com.example.app.nativeqt {} (null), Failed at LSRegister/LSRegisterApplicationService for com.example.app.nativeqt, ERROR -1027: Invalid permissions for com.example.app.nativeqt-1408 (_LSTransportRequestName @ transport.c:2038)

May 20 20:56:20 qemux86-64 nativeqt[1408]: [pmlog] NATIVE_QML_APP com.example.app.nativeqt {} (null), Failed to initialize LunaServiceManager instance for appId: "com.example.app.nativeqt"

Thank you,

Hi @cphong, welcome to the forum.

Could you check the validation of your codes using QML app?

Thanks

Hi @NERGI ,

Yes, I may utilize the qml-webos-bridge plugin if I make my project a built-in QML application. However, I'd like to develop certain elements in C++ rather than QML. Do you have any suggestions?

Thank you,

@cphong,

I think your main.cpp is not properly set.

You can use both C++ and QML in one project, but if you use them in one file it can occur errors. Choose Window and QGuiApplication depending on your main file (using the main.qml, you should use QGuiApplication).

Thanks

Hi @NERGI ,

I'm not sure what I did wrong in my code. I can load the main.qml file and display it properly.
However, the issues arise when I utilize the component Service provided by the qml-webos-bridge plugin.

If you don't mind, could you please review my source code?

main.cpp

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <PmLog.h>

static PmLogContext getPmLogContext()
{
    static PmLogContext s_context = 0;
    if (s_context)
    {
        PmLogGetContext("NativeQT", &s_context);
    }
    return s_context;
}

static void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message)
{
    switch (type)
    {
        case QtDebugMsg:
            PmLogDebug(getPmLogContext(), "%s, %s", context.function, message.toUtf8().data());
            break;
        case QtWarningMsg:
            PmLogWarning(getPmLogContext(), "com.example.app.nativeqt", 0, "%s, %s", context.function, message.toUtf8().data());
            break;
        case QtCriticalMsg:
            PmLogError(getPmLogContext(), "com.example.app.nativeqt",  0, "%s, %s", context.function, message.toUtf8().data());
            break;
        case QtFatalMsg:
            PmLogCritical(getPmLogContext(), "com.example.app.nativeqt",  0, "%s, %s", context.function, message.toUtf8().data());
            break;
        default:
            PmLogDebug(getPmLogContext(), "%s, %s", context.function, message.toUtf8().data());
    }
}

int main(int argc, char** argv)
{
    qInstallMessageHandler(messageHandler);

    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    if (engine.rootObjects().isEmpty())
        return -1;

    return app.exec();
}

main.qml

import QtQuick 2.4
import WebOSServices 1.0
import Eos.Window 0.1
import PmLog 1.0

WebOSWindow {
    id: root
    width: 1920
    height: 1080
    visible: true
    appId: "com.example.app.nativeqt"
    title: "Native QT"
    color: "lightblue"

    Text {
        id: mainText
        anchors.centerIn: parent
        font.family: "Helvetica"
        font.pointSize: 50
        text: "Hello, Native QT Application!!"
    }

    Service {
        id: systemService
        appId: "com.example.app.nativeqt"

        function getTime() {
            call("luna://com.webos.service.systemservice", "/clock/getTime", "{}")
        }

        onResponse: {
            var jsonObject = JSON.parse(payload);
            pmLog.info("GETTIME", {"utc": jsonObject.utc});
            mainText.text = "UTC : " + jsonObject.utc
        }

        onError: {
            var jsonObject = JSON.parse(payload);
            pmLog.error("GETTIME", {"error": jsonObject});
        }
    }

    MouseArea {
        anchors.fill: parent
        onClicked: systemService.getTime()
    }

    PmLog {
        id: pmLog
        context: "NativeQT"
    }
}

com.example.app.nativeqt.pro

TARGET = nativeqt

CONFIG += qt
QT += qml

CONFIG += link_pkgconfig
PKGCONFIG += PmLogLib

SOURCES += main.cpp

RESOURCES += qml.qrc

INSTALL_APPDIR = $${WEBOS_INSTALL_WEBOS_APPLICATIONSDIR}/com.example.app.nativeqt

target.path = $${INSTALL_APPDIR}

icon.path = $${INSTALL_APPDIR}
icon.files = icon.png

appinfo.path = $${INSTALL_APPDIR}
appinfo.files = appinfo.json

INSTALLS += target icon appinfo

appinfo.json

{
    "id": "com.example.app.nativeqt",
    "version": "0.0.1",
    "vendor": "My Company",
    "type": "native",
    "main": "nativeqt",
    "title": "Native qt App",
    "icon": "icon.png",
    "requiredPermissions" : ["application.operation"],
    "nativeLifeCycleInterfaceVersion": 2
}

com.example.app.nativeqt.bb

SUMMARY = "Native QT App"
SECTION = "webos/apps"
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"

DEPENDS = "qtbase qt-features-webos qtdeclarative pmloglib"
RDEPENDS:${PN} += "qml-webos-framework qml-webos-bridge"

WEBOS_VERSION="1.0.0"
PR = "r0"

inherit webos_qmake6
inherit webos_submissions
inherit webos_app

FILES:${PN} += "${webos_applicationsdir}"

Sorry, this page does not allow me to attach the zip file.

@cphong,

Our developer has confirmed that your source code can be built through some modification.

  1. Add the time.query permission to your appinfo.json file.
  2. Package your source code: bitbake <your package>.
  3. Install the IPK file.
  4. In your OSE machine, go to /usr/share/luna-service2/role.d.
  5. Change the type: from "regular" to "privileged". The getTime API needs this permission.
  6. Reboot.
  7. Your app might run as expected.

Thanks!

1 Like