[SOLVED] Need help at creating components module
-
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 pluginTARGET = $$qtLibraryTarget($$TARGET)
uri = TestUiInput
SOURCES +=
test_ui_plugin.cpp
test_button_item.cppHEADERS +=
test_ui_plugin.h
test_button_item.hOTHER_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;
}@<edit>
qmldir
@module TestUi
plugin test_ui@
</edit>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.1Rectangle {
width: 360
height: 360
Button {
id: button
borderColor: "blue"
text: "Button"
}
}@<edit>
Some Information:
I use Qt 5.0.2 installed via qt-windows-opensource-5.0.2-msvc2012_64-x64-offline.exe on Win7 64bit with Visual Studio 2012 Express for Windows Desktop.
</edit>I hope you guys can help me with this. Thank you.
-
Where have you installed your module to? It should be something like: $QT_DIR/qml/TestUi/
Did you run "(n)make install" after building your module?Have you defined a module specification qmldir file? It's listed in your .pro but not included in your post. I assume it's just a 2-liner, specifying the module name and the plugin name?
Cheers,
Chris. -
Hi Chris,
first thank you for your reply. :) Yes i used "nmake install" to install the libs (release and debug versions) and the qmldir at QT_INSTALL_IMPORTS/TestUi where QT_INSTALL_IMPORTS stands for C:\Qt\Qt5.0.2\5.0.2\msvc_64\imports on my machine.
I edited my post and included the qmldir and some other information.
-
I believe it should be QT_INSTALL_QML with Quick2 as Chris suggested.
-
Yep you where right. It has to be in the qml folder not in the import folder.
Thank you very much. :)