Qt doesn't find my imported module
When i build a plugin using qmake and make command, it creates a directory called release, which contains the .dll file.
My question is how can i use this plugin in Qt Quick Application?
I have tried in the .pro file QML_IMPORT_PATH += C:/Programming/Qt/test2/release And in the main.qml file import myplugin 1.0. But when i try to run the application it doesn't find the imported plugin.
Lets say i have a simple plugin like this that just sends s signal that contains a message :
myitem.h
#ifndef MYITEM_H
#define MYITEM_H
#include <QObject>
#include <QString>
#include <QTimer>
#include <QDebug>
class MyItem : public QObject
{
Q_OBJECT
public:
explicit MyItem(QObject *parent = nullptr);
~MyItem();
signals:
void mySignal(const QString &message);
public slots:
void sendMessage();
};
#endif // MYITEM_H
myitem.cpp:
#include "myitem.h"
MyItem::MyItem(QObject *parent) : QObject(parent)
{
QTimer::singleShot(1000, this, &MyItem::sendMessage);
}
MyItem::~MyItem() {}
void MyItem::sendMessage()
{
qDebug() << "Sending signal with message: Hello from C++!";
emit mySignal("Hello from C++!");
}
test2_plugin.h:
#ifndef TEST2_PLUGIN_H
#define TEST2_PLUGIN_H
#include <QQmlExtensionPlugin>
class Test2Plugin : public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
public:
void registerTypes(const char *uri) override;
};
#endif // TEST2_PLUGIN_H
test2plugin.cpp:
#include "test2_plugin.h"
#include "myitem.h"
#include <qqml.h>
void Test2Plugin::registerTypes(const char *uri)
{
// @uri myplugin
qmlRegisterType<MyItem>(uri, 1, 0, "MyItem");
}
qmldir:
module myplugin
plugin test2
Qt doesn't find my imported module
When i build a plugin using qmake and make command, it creates a directory called release, which contains the .dll file.
My question is how can i use this plugin in Qt Quick Application?
I have tried in the .pro file QML_IMPORT_PATH += C:/Programming/Qt/test2/release And in the main.qml file import myplugin 1.0. But when i try to run the application it doesn't find the imported plugin.
Lets say i have a simple plugin like this that just sends s signal that contains a message :
myitem.h
#ifndef MYITEM_H
#define MYITEM_H
#include <QObject>
#include <QString>
#include <QTimer>
#include <QDebug>
class MyItem : public QObject
{
Q_OBJECT
public:
explicit MyItem(QObject *parent = nullptr);
~MyItem();
signals:
void mySignal(const QString &message);
public slots:
void sendMessage();
};
#endif // MYITEM_H
myitem.cpp:
#include "myitem.h"
MyItem::MyItem(QObject *parent) : QObject(parent)
{
QTimer::singleShot(1000, this, &MyItem::sendMessage);
}
MyItem::~MyItem() {}
void MyItem::sendMessage()
{
qDebug() << "Sending signal with message: Hello from C++!";
emit mySignal("Hello from C++!");
}
test2_plugin.h:
#ifndef TEST2_PLUGIN_H
#define TEST2_PLUGIN_H
#include <QQmlExtensionPlugin>
class Test2Plugin : public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
public:
void registerTypes(const char *uri) override;
};
#endif // TEST2_PLUGIN_H
test2plugin.cpp:
#include "test2_plugin.h"
#include "myitem.h"
#include <qqml.h>
void Test2Plugin::registerTypes(const char *uri)
{
// @uri myplugin
qmlRegisterType<MyItem>(uri, 1, 0, "MyItem");
}
qmldir:
module myplugin
plugin test2
- My first advice would be to change to cmake as your build system. Many cmake macros make using modules much easier. – Jürgen Lutz Commented Mar 11 at 10:45
1 Answer
Reset to default 0If you mean running as a stand alone application and not throught Qt Creator you have at least two solutions
You can copy each plugin/module folder next to the executable you want to run
Each module must be in separate folders and include qmldir and library and/or qml files
yourapplication
ModuleOne
|-qmldir
|-pluginone.so
|-ComponentOne.qml
|-ComponentTwo.qml
ModuleTwo
|-qmldir
|-plugintwo.so
You have also the possibility to put all plugins/modules folder in a dedicated directory and set both env variable QML_IMPORT_PATH and QML2_IMPORT_PATH to this directory before running the application