From b86be10882236d269817c42daa1bc3fa49fe78af Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Sat, 28 Dec 2013 17:02:06 +0100 Subject: Fixup and cleanup examples to make them work properly. This fixes some regressions introduced by previous commits and ensures that the examples work as intended. While at it, the code is cleaned up a bit by using resources instead of referencing files in the source dir. Change-Id: I01da305429dcdebcb96284b7110c59f3090b2201 Reviewed-by: Simon Hausmann --- examples/hybridshell/hybridshell.pro | 7 ++++++- examples/hybridshell/main.cpp | 5 ++--- examples/hybridshell/main.qml | 5 +++-- examples/hybridshell/resources.qrc | 6 ++++++ examples/qtobject/main.cpp | 7 +++---- examples/qtobject/main.qml | 5 +++-- examples/qtobject/qtobject.pro | 7 ++++++- examples/qtobject/resources.qrc | 6 ++++++ 8 files changed, 35 insertions(+), 13 deletions(-) create mode 100644 examples/hybridshell/resources.qrc create mode 100644 examples/qtobject/resources.qrc (limited to 'examples') diff --git a/examples/hybridshell/hybridshell.pro b/examples/hybridshell/hybridshell.pro index 2660d30..4ff38db 100644 --- a/examples/hybridshell/hybridshell.pro +++ b/examples/hybridshell/hybridshell.pro @@ -9,4 +9,9 @@ SOURCES += \ HEADERS += \ shell.h -DEFINES += "SOURCE_DIR=\"\\\""$$PWD"\\\"\"" +RESOURCES += \ + resources.qrc + +OTHER_FILES += \ + main.qml \ + index.html diff --git a/examples/hybridshell/main.cpp b/examples/hybridshell/main.cpp index d57966f..8c7e9b0 100644 --- a/examples/hybridshell/main.cpp +++ b/examples/hybridshell/main.cpp @@ -41,11 +41,10 @@ int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); - qmlRegisterType("Qt.labs", 1, 0, "HybridShell"); + qmlRegisterType("QtWebChannel.Examples", 1, 0, "HybridShell"); QQuickView viewer; - viewer.engine()->addImportPath(app.applicationDirPath() + QStringLiteral("/../../src/")); - viewer.setSource(QUrl::fromLocalFile(QStringLiteral(SOURCE_DIR) + QStringLiteral("/main.qml"))); + viewer.setSource(QStringLiteral("qrc:/main.qml")); viewer.show(); return app.exec(); diff --git a/examples/hybridshell/main.qml b/examples/hybridshell/main.qml index 0dedb74..24dc729 100644 --- a/examples/hybridshell/main.qml +++ b/examples/hybridshell/main.qml @@ -42,6 +42,7 @@ import QtQuick 2.0 import QtWebChannel 1.0 +import QtWebChannel.Examples 1.0 import QtWebKit 3.0 import QtWebKit.experimental 1.0 @@ -66,12 +67,12 @@ Rectangle { onInitialized: { shell.start() - webView.url = "index.html?webChannelBaseUrl=" + webChannel.baseUrl; + webView.url = "qrc:/index.html?webChannelBaseUrl=" + webChannel.baseUrl; } } width: 480 - height: 800 + height: 600 WebView { id: webView diff --git a/examples/hybridshell/resources.qrc b/examples/hybridshell/resources.qrc new file mode 100644 index 0000000..b93a6b2 --- /dev/null +++ b/examples/hybridshell/resources.qrc @@ -0,0 +1,6 @@ + + + index.html + main.qml + + diff --git a/examples/qtobject/main.cpp b/examples/qtobject/main.cpp index f11f4ba..4436862 100644 --- a/examples/qtobject/main.cpp +++ b/examples/qtobject/main.cpp @@ -41,12 +41,11 @@ int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); - qmlRegisterType("Qt.labs", 1, 0, "TestObjectFactory"); - qmlRegisterType("Qt.labs", 1, 0, "TestObject"); + qmlRegisterType("QtWebChannel.Examples", 1, 0, "TestObjectFactory"); + qmlRegisterType("QtWebChannel.Examples", 1, 0, "TestObject"); QQuickView viewer; - viewer.engine()->addImportPath(app.applicationDirPath() + QStringLiteral("/../../src/")); - viewer.setSource(QUrl::fromLocalFile(QStringLiteral(SOURCE_DIR) + QStringLiteral("/main.qml"))); + viewer.setSource(QStringLiteral("qrc:/main.qml")); viewer.show(); return app.exec(); diff --git a/examples/qtobject/main.qml b/examples/qtobject/main.qml index 6dd82fa..76ef3d9 100644 --- a/examples/qtobject/main.qml +++ b/examples/qtobject/main.qml @@ -42,6 +42,7 @@ import QtQuick 2.0 import QtWebChannel 1.0 +import QtWebChannel.Examples 1.0 import QtWebKit 3.0 import QtWebKit.experimental 1.0 @@ -63,7 +64,7 @@ Rectangle { id: webChannel onRawMessageReceived: { - if (!publisher.handleRequest(rawMessage, webChannel)) { + if (!publisher.handleRawMessage(rawMessage)) { console.log("unhandled request: ", rawMessage); } } @@ -74,7 +75,7 @@ Rectangle { "initialTestObject": testObject }); - webView.url = "index.html?webChannelBaseUrl=" + webChannel.baseUrl; + webView.url = "qrc:/index.html?webChannelBaseUrl=" + webChannel.baseUrl; } } diff --git a/examples/qtobject/qtobject.pro b/examples/qtobject/qtobject.pro index e893d23..557603a 100644 --- a/examples/qtobject/qtobject.pro +++ b/examples/qtobject/qtobject.pro @@ -9,4 +9,9 @@ SOURCES += \ HEADERS += \ testobject.h -DEFINES += "SOURCE_DIR=\"\\\""$$PWD"\\\"\"" +RESOURCES += \ + resources.qrc + +OTHER_FILES += \ + main.qml \ + index.html diff --git a/examples/qtobject/resources.qrc b/examples/qtobject/resources.qrc new file mode 100644 index 0000000..b93a6b2 --- /dev/null +++ b/examples/qtobject/resources.qrc @@ -0,0 +1,6 @@ + + + index.html + main.qml + + -- cgit v1.2.1