Qt Qml 插件导入

参考 文章:

https://www.cnblogs.com/senior-engineer/p/5596976.html

导入qml插件主要分两个步骤:

1.main.cpp 代码例子

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include "roleentrymodel.h"
#include<QtQml>
#include "colormaker.h"
#include "person.h"
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
 
 
    QGuiApplication app(argc, argv);
    qmlRegisterType<ColorMaker>("an.qt.ColorMaker",1,0,"ColorMaker");
    QQmlApplicationEngine engine;
    engine.addImportPath("../derivaticeTrading/plugin");
    QStringList mylist = engine.importPathList();
    for (auto i = 0 ; i <  mylist.size();i++) {
        cout <<"list =>" <<  mylist.at(i).toLocal8Bit().constData() << endl;
    }
    //engine.addImportPath("./demo");
    engine.load(QUrl(QStringLiteral("qrc:/view/main.qml")));
    if (engine.rootObjects().isEmpty())
        return -1;
    return app.exec();
}
 
 

pro文件样例

TEMPLATE = app
 
 
QT += qml quick
CONFIG += c++11
 
 
 
 
 
 
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH = $$PWD/plugin/
message($$QML_IMPORT_PATH)
# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =
 
 
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
 
 
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
 
 
# Default rules for deployment.
 
 
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
 
 
HEADERS += \
    src/roleentrymodel.h \
    src/colormaker.h \
    src/person.h
 
 
SOURCES += src/main.cpp \
    src/roleentrymodel.cpp \
    src/colormaker.cpp  \
    src/person.cpp
 
 
RESOURCES += qml.qrc

被导入的插件 文件内部含有qmdir文件,且文件写法如下:

qmdir

扫描二维码关注公众号,回复: 2687798 查看本文章
module Material
则改上层文件夹名字应该是 Material 
 


猜你喜欢

转载自blog.csdn.net/a314315805/article/details/79097528