首页 > 代码库 > How To Add QML Module with Plugins for Qt Creator

How To Add QML Module with Plugins for Qt Creator

I decided to take a plunge into a KDE Plasma development with a simple plasmoid with Qt Creator. There’s a very good overview and a guide

  • Getting Started Plasma QML tutorial

  • Getting Started Programming with QML

However, you will notice that when you do this in Qt Creator

import org.kde.plasma.core 0.1 as PlasmaCore

you will get an underline and the following error

QML module not found

followed by import paths and some vague tip about QML_IMPORT_PATH and importPaths property. What this means is that you need to explicitly declare the import path for KDE components in your *.qmlproject file. Specifically, directly in/under the Project container add the following property

importPaths: [ "/usr/lib64/kde4/imports" ]

or whatever the case is for your specific environment. Now switching back to your .qml file you will notice that the red underline is still there but the message is different when you hover over it

QML module does not contain information contained in plugins

First, the QML can be run at this point. Second, this is because KDE has not included plugins.qmltypes files with their Plasma components. To generate them yourself you can run a command

qmlplugindump org.kde.plasma.core 0.1 /usr/lib64/kde4/imports > /usr/lib64/kde4/imports/org/kde/plasma/plugins.qmltypes

substituting your paths, if different. You’ll note that your user probably doesn’t have privileges to write to that directory – so either run the command as root or generate the file in another directory and then copy it.

After refreshing/reloading the project in Qt Creator you will see the red underline has disappeared and Qt Creator is in a happy state. You can use this method with other components with missing plugins.qmltypes files; and use this with your custom C++ components as well.

How To Add QML Module with Plugins for Qt Creator