Hi, I created a components module using the Qt Creator template for QtQuick 2 and the building runs fine but when i want to use the module i get an error saying that my module isn’t installed:
file:///C:/Users/Paul/Documents/QtCreator/src/component_test/component_test.qml:2 module "TestUi" is not installed
The Project:
test_ui.pro
TEMPLATE = lib
TARGET = test_ui
QT += qml quick
CONFIG += qt plugin
TARGET = $$qtLibraryTarget($$TARGET)
uri = TestUi
# Input
SOURCES += \
test_ui_plugin.cpp \
test_button_item.cpp
HEADERS += \
test_ui_plugin.h \
test_button_item.h
OTHER_FILES = qmldir
!equals(_PRO_FILE_PWD_, $$OUT_PWD) {
copy_qmldir.target = $$OUT_PWD/qmldir
copy_qmldir.depends = $$_PRO_FILE_PWD_/qmldir
copy_qmldir.commands = $(COPY_FILE) \"$$replace(copy_qmldir.depends, /, $$QMAKE_DIR_SEP)\" \"$$replace(copy_qmldir.target, /, $$QMAKE_DIR_SEP)\"
QMAKE_EXTRA_TARGETS += copy_qmldir
PRE_TARGETDEPS += $$copy_qmldir.target
}
qmldir.files = qmldir
installPath = $$[QT_INSTALL_IMPORTS]/$$replace(uri, \\., /)
qmldir.path = $$installPath
target.path = $$installPath
INSTALLS += target qmldir
test_ui_plugin.h
#ifndef TEST_UI_PLUGIN_H
#define TEST_UI_PLUGIN_H
#include <QQmlExtensionPlugin>
class TestUiPlugin : public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
public:
void registerTypes(const char *uri);
};
#endif // TEST_UI_PLUGIN_H
test_ui_plugin.cpp
#include "test_ui_plugin.h"
#include "test_button_item.h"
#include <qqml.h>
void TestUiPlugin::registerTypes(const char *uri)
{
// @uri TestUi
qmlRegisterType<TestButtonItem>(uri, 0, 1, "Button");
}
test_button_item.h
#ifndef TESTBUTTONITEM_H
#define TESTBUTTONITEM_H
#include <QQuickPaintedItem>
class TestButtonItem : public QQuickPaintedItem
{
Q_OBJECT
Q_DISABLE_COPY(TestButtonItem)
Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor)
Q_PROPERTY(QString text READ text WRITE setText)
public:
TestButtonItem(QQuickPaintedItem *parent = 0);
~TestButtonItem();
QColor borderColor() const;
void paint(QPainter *painter);
void setBorderColor(const QColor& color);
void setText(const QString& text);
QString text() const;
private:
QColor m_qcolorBorderColor;
QString m_qstringText;
};
QML_DECLARE_TYPE(TestButtonItem)
#endif // TESTBUTTONITEM_H
test_button_item.cpp
#include "test_button_item.h"
#include <QPainter>
#include <QPen>
TestButtonItem::TestButtonItem(QQuickPaintedItem *parent)
: QQuickPaintedItem(parent) {
setBorderColor(QColor(Qt::black));
setImplicitHeight(50.0);
setImplicitWidth(100.0);
}
TestButtonItem::~TestButtonItem() {
}
QColor TestButtonItem::borderColor() const {
return m_qcolorBorderColor;
}
void TestButtonItem::paint(QPainter* painter) {
QPen qpen(borderColor(), 3);
painter->setPen(qpen);
painter->drawRect(0, 0, width(), height());
painter->drawText(0, 0, width(), height(), Qt::AlignCenter, m_qstringText);
}
void TestButtonItem::setBorderColor(const QColor& color) {
m_qcolorBorderColor = color;
}
void TestButtonItem::setText(const QString& text) {
m_qstringText = text;
}
QString TestButtonItem::text() const {
return m_qstringText;
}
The Test App
components_test.qmlproject
/* File generated by Qt Creator, version 2.7.0 */
import QmlProject 1.1
Project {
mainFile: "components_test.qml"
/* Include .qml, .js, and image files from current directory and subdirectories */
QmlFiles {
directory: "."
}
JavaScriptFiles {
directory: "."
}
ImageFiles {
directory: "."
}
/* List of plugin directories passed to QML runtime */
// importPaths: [ "../exampleplugin" ]
}
components_test.qml
import QtQuick 2.0
import TestUi 0.1
Rectangle {
width: 360
height: 360
Button {
id: button
borderColor: "blue"
text: "Button"
}
}
I hope you guys can help me with this. Thank you.
↧