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.