aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTopi Reinio <topi.reinio@theqtcompany.com>2016-01-12 13:37:42 +0100
committerJake Petroules <jake.petroules@qt.io>2016-04-16 02:25:23 +0000
commit35e2f29cde8dc8280b5ce1986533fca63f902d5e (patch)
tree2d7cb2ebc2b1222be6de8efa9e17a309bde237fc
parent49ca8921ba026397c287da974ced7d890a5a28d3 (diff)
QML extensions tutorial: Add import plugin to app. bundle on OS X
The application in chapter 6 of this tutorial failed to import the custom extension plugin on OS X, as it could not see it's import path outside the application bundle. Change-Id: Icdca1f0553020e0460e4efabc5461a3447b32086 Task-number: QTBUG-47003 Reviewed-by: Leena Miettinen <riitta-leena.miettinen@theqtcompany.com> Reviewed-by: Jake Petroules <jake.petroules@qt.io>
-rw-r--r--examples/qml/tutorials/extending-qml/chapter6-plugins/app.pro11
-rw-r--r--examples/qml/tutorials/extending-qml/chapter6-plugins/main.cpp10
-rw-r--r--src/qml/doc/src/cppintegration/extending-tutorial.qdoc26
3 files changed, 35 insertions, 12 deletions
diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/app.pro b/examples/qml/tutorials/extending-qml/chapter6-plugins/app.pro
index c55db00d27..4d0e807417 100644
--- a/examples/qml/tutorials/extending-qml/chapter6-plugins/app.pro
+++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/app.pro
@@ -1,10 +1,15 @@
TARGET = chapter6-plugins
QT += qml quick
-# Avoid going to debug/release subdirectory
-# so that our application will see the
-# import path for the Charts module.
+# Ensure that the application will see the import path for the Charts module:
+# * On Windows, do not build into a debug/release subdirectory.
+# * On OS X, add the plugin files into the bundle.
win32: DESTDIR = ./
+osx {
+ charts.files = $$OUT_PWD/Charts
+ charts.path = Contents/PlugIns
+ QMAKE_BUNDLE_DATA += charts
+}
SOURCES += main.cpp
RESOURCES += app.qrc
diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/main.cpp b/examples/qml/tutorials/extending-qml/chapter6-plugins/main.cpp
index b20ae35f92..d165513861 100644
--- a/examples/qml/tutorials/extending-qml/chapter6-plugins/main.cpp
+++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/main.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
+** Copyright (C) 2016 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
@@ -37,17 +37,21 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-//![0]
#include <QtQuick/QQuickView>
#include <QGuiApplication>
+#include <QQmlEngine>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
+//![0]
QQuickView view;
+#ifdef Q_OS_OSX
+ view.engine()->addImportPath(app.applicationDirPath() + "/../PlugIns");
+#endif
+//![0]
view.setResizeMode(QQuickView::SizeRootObjectToView);
view.setSource(QUrl("qrc:///app.qml"));
view.show();
return app.exec();
}
-//![0]
diff --git a/src/qml/doc/src/cppintegration/extending-tutorial.qdoc b/src/qml/doc/src/cppintegration/extending-tutorial.qdoc
index d862b50fcb..c0cfc3e1aa 100644
--- a/src/qml/doc/src/cppintegration/extending-tutorial.qdoc
+++ b/src/qml/doc/src/cppintegration/extending-tutorial.qdoc
@@ -386,12 +386,26 @@ directory.
\quotefile tutorials/extending-qml/chapter6-plugins/import/import.pro
-In this example, the \c Charts directory is located at the same level as the application
-that uses our new import module. This way, the QML engine will find our module
-as the default search path for QML imports includes the directory of the application
-executable. Alternatively, we could control what directories the \l {QML Import Path}
-{QML import path} contains, useful if there are multiple QML applications using the
-same QML imports.
+When building this example on Windows or Linux, the \c Charts directory will be
+located at the same level as the application that uses our new import module.
+This way, the QML engine will find our module as the default search path for QML
+imports includes the directory of the application executable. On OS X, the
+plugin binary is copied to \c Contents/PlugIns in the the application bundle;
+this path is set in \l {tutorials/extending-qml/chapter6-plugins/app.pro}
+{chapter6-plugins/app.pro}:
+
+\quotefromfile tutorials/extending-qml/chapter6-plugins/app.pro
+\skipto osx
+\printuntil }
+
+To account for this, we also need to add this location as a
+\l {QML Import Path}{QML import path} in \c main.cpp:
+
+\snippet tutorials/extending-qml/chapter6-plugins/main.cpp 0
+\dots
+
+Defining custom import paths is useful also when there are multiple
+applications using the same QML imports.
The \c .pro file also contains additional magic to ensure that the
\l {Module Definition qmldir Files}{module definition qmldir file} is always copied