The code in the tutorial "Writing QML Extensions with C++" for Chapter 6 does not find the created plugin
-
Hello everybody,
I am pretty new to Qt and QML, and I am working myself through the tutorials and examples to learn how to create my own QML plugins. But, I have a problem with chapter 6 from the otherwise great "Writing QML Extensions with C++":http://doc.qt.io/qt-5/qtqml-tutorials-extending-qml-example.html tutorial. I cannot get the application to find the built Charts plugin. I get the following output from my executable:
@qrc:///app.qml:41:1: module "Charts" is not installed@
I have tried both the files from the built-in examples and from the web, and both fail with this message. I am on Mac OSX Yosemite 10.10.1, with a standard Qt 5.4 installation downloaded from qt.io using Qt Creator for editing the files and building the application (with the clang64 standard build settings).
I already tried some possible solutions I found in various locations on the web, like...
- setting QML2_IMPORT_PATH from app.pro to include the imports/ folder
- using QQmlApplicationEngine in main.cpp to add the imports folder through ::addImportPath()
...but nothing succeeded. I always get the aforementioned error. Does anyone now the usual/common/best practice for this standard problem? I could not find any resource covering this. Considering that it is part of a standard tutorial delivered with every Qt installation that does not work out of the box (at least not on Mac OSX 10.10), I would like to improve the tutorial with the necessary information.
Apart from getting the basic example to work, here's just another question that comes up for me: Shouldn't the .dylib containing the QML plugin be copied into the application bundle? At the moment it gets only copied to the imports/ folder inside the build folder that Qt Creator creates while building, along with the qmldir file.
Thank you very much!
Cheers,
jmaibaum -
I found the same problem, the thing is that when you build in Mac, it generates a bundle .app, which is a directory containing the executable file within some subfolders (if you right click it in finder, and click show contents, you will see the internal composition of the package, and you will find the proper executable). That is the reason why it is not able to find the Charts folder. In the .pro file, you can add CONFIG -= app_bundle, that will generate a bundle-less executable instead, and therefore it will see the Charts folder, and it will work. Alternatively, you could try to find a way of getting the plugin folder (Charts) inside the bundle automatically (I assume there is a way to do this?).