Problem using Qml from within a shared library.
-
I have been trying to use a .qml file to build a UI for my plugin to a 3rd party application but when I try to view the Qml from a QQuickWidget or QQuickView in the dll plugin file, I only get a blank widget or view.
For testing purposes I have been using the dockwidgets example project from Qt 5.5.1 Examples and added a new dockwidget that uses a QQuickWidget to load the qml file.
If I use the same code to create an .exe file in a standalone project, then the qml displays just fine in the QQuickWidget.
If I use the exact code (except for the main.cpp) in a dll file that is loaded into my 3rd party app then everything works in the example except the widget that loads the qml file is blank.
Should I be able to use Qml from a dll as I am trying?
Any help would be appreciated. I am using Windows 10 Pro x64 and I built Qt using VS 2012 to get a x64 build of Qt.
I've tried loading the file directly using the full path to the file and by using a .qrc file which points to the qml file location in a local folder in the project.
Here is the code that I added to the createDockWindows() function in mainwindow.cpp of the dockwidgets example.
dock = new QDockWidget(tr("View Qml"), this); viewQml = new QQuickWidget(dock); viewQml->setSource(QUrl::fromLocalFile("qml/myTestmain.qml")); viewQml->show(); dock->setWidget(viewQml); addDockWidget(Qt::RightDockWidgetArea, dock);
I created a new folder (qml) in the dockwidgets folder to hold the qml file.
I use the following function in my dll plugin to create the Qt window:
CreateQtWindow() { QApplication app(argc, argv); Q_INIT_RESOURCE(dockwidgets); MainWindow mainWindow; mainWindow.show(); return app.exec(); }
-
Is this third party app a Qt app?
I'm asking because you create a QApplication instance and a Qt app should only have one such instance. -
@jsulm The 3rd party app is not a Qt app.
I can get the dockwidgets example code to run in the dll except for the QQuickWidget that loads the qml doesn't display anything. It's as if the qml file cannot be found, however, I have tried various ways of specifying the location of the qml including the use of a .qrc file.
-
Can you verify that the QML file can be accessed? You could for example try to open it using QFile.
-
@jsulm I used QFile and the file is found and accessed.
I found that the QQuickWidget is getting status errors of the following:
module "QtQuick" is not installed and module "QtQuick.Controls" is not installed.
I've tried using QQmlEngine::addImportPath() to specify the path to the QtQuick files but haven't had any luck getting this to work.
-
I got the qml to display in the QQuickWidget but it was strictly by trial and error.
I used the QmlEngine::importPathList() function to find out what paths were being searched for the imports and found that there were two paths being listed. One for the bin folder of my 3rd Party App install path and bin/qml of the 3rd Party app install path.
I tried specifying the location of the qml import files supplied by Qt by using QQmlEngine::addImportPath() to add the path to where the Qt qml files were located but this did not work. The added path shows as being added properly when using the QQmlEngine::importPathList() to list out the paths but it didn't seem to be used to find the QtQuick or QtQuick.Controls modules needed by my qml file.
I then copied the qml folder from my Qt build to the 3rd Party App bin folder and then the QtQuick and QtQuick.Controls modules were installed and the qml was loaded and displayed in the QQuickWidget.
-
After further testing with the QQmlEngine::addImportPaths(), QQmlEngine::addPluginPaths(), QQmlEngine::setImportPathList() and QQmlEngine::setPluginPathList() functions none of these allowed the QtQuick and QtQuick.Controls qml modules to be found and installed.
I then added the QML2_IMPORT_PATH environment variable and set it to point to my Qt build qml folder D:/qt-5.5.1_vs2012x64/qt_build/qtbase/qml and this worked.
Question is why don't the paths added by the QQmlEngine functions work? The paths are added but don't seem to be searched.