Я хочу связать только dll и только файл заголовка.
Как должен быть структурирован файл .pro и класс dll?
Как я могу импортировать в основной проект?
это код dll .pro:
Код: Выделить всё
QT += core gui quick qml
CONFIG += dll
TARGET = MyQmlDll
TEMPLATE = lib
SOURCES += \
main.cpp \
src/myclass.cpp
HEADERS += \
src/MyLibrary_global.h \
src/myclass.h
# Include path for QML
RESOURCES += qml.qrc
# Define output path
DESTDIR = $$PWD/lib
DISTFILES += \
qmldir
Код: Выделить всё
#include
#include
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.addImportPath("./../MyLibrary/lib");
const QUrl url(QStringLiteral("qrc:/MainP/main.qml"));
QObject::connect(
&engine,
&QQmlApplicationEngine::objectCreated,
&app,
[url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
},
Qt::QueuedConnection);
engine.load(url);
return app.exec();
}
Код: Выделить всё
QT += quick
# Aggiungi il percorso del DLL
QML_IMPORT_PATH += $$PWD/../MyLibrary/lib
# Aggiungi il percorso della directory delle librerie
LIBS += -L$$PWD/../MyLibrary/lib/MyQmlDll.dll
SOURCES += \
main.cpp
resources.files = main.qml
resources.prefix = /$${TARGET}
RESOURCES += resources
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
Код: Выделить всё
#include
#include
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.addImportPath("./../MyLibrary/lib");
const QUrl url(QStringLiteral("qrc:/MainP/main.qml"));
QObject::connect(
&engine,
&QQmlApplicationEngine::objectCreated,
&app,
[url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
},
Qt::QueuedConnection);
engine.load(url);
return app.exec();
}
Код: Выделить всё
import QtQuick
import MyQmlDll
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
// Usa il componente definito nel DLL
MyClass { // Proprietà e metodi del componente
}
// Usa l'oggetto QML definito nel DLL
MyQmlObject {
// Proprietà e metodi dell'oggetto QML
}
}
QQmlApplicationEngine не удалось загрузить компонент
qrc:/MainP/main.qml:2:1 : модуль "MyQmlDll" не установлен
не могу понять почему.
Подробнее здесь: https://stackoverflow.com/questions/791 ... osed-class
Мобильная версия