Qt 5 - qmlRegisterType gives "module is not installed".
-
Hello,
I am having a small problem with registering custom type in QML. I believe, I've missed something, anyway, I am having such error:
@
qrc:/img/gameContent01.qml:2:1: module "myproject.ui" is not installed
@GameWidget.h
@
#ifndef GAMEWIDGET_H
#define GAMEWIDGET_H#include <QObject>
#include <QString>
#include <QImage>class GameWidget : public QObject
{
Q_OBJECT
Q_PROPERTY(QString title READ getTitle WRITE setTitle NOTIFY titleChanged)public:
explicit GameWidget(QObject *parent = 0) : QObject(parent) { };
~GameWidget();QString getTitle() const;
void setTitle(const QString& title);signals:
void titleChanged();private:
QString m_title;
};
#endif
@mainwindow.cpp
@
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);qmlRegisterType<GameWidget>("myproject.ui", 1, 0, "GameWidget");
///
}
@#uml file
@
import QtQuick 1.1
import myproject.ui 1.0
@ -
Perhaps you are performing the registration too late? Try at least moving it before setupUi() is called.
-
[quote author="sierdzio" date="1390303909"]Perhaps you are performing the registration too late? Try at least moving it before setupUi() is called.[/quote]
I've tried it, and it didn't change anything. I've also tried to add this line in main.cpp, before creating MainWindow object - it also didn't work.
-
Facing the same error here, registration is made before loading any QML and I still get the error of the module not being installed when I try to run the QML file.
My code looks like this:
@
int GuiThread::svc(void)
{
int argc;
char *argv[1];
GuiApplication app;qmlRegisterType<ItemsFilter>("backEndComponents", 1,0, "ItemsFilter");
QQuickView *poView = new QQuickView;poView->setSource(QUrl::fromLocalFile("pkg/visufrwk/pkg/plugins/adapt/dummy.qml")); QMainWindow *poMainWindow = new QMainWindow(); QWidget *poWidget = new QWidget(poMainWindow); poWidget = QWidget::createWindowContainer(poView); poMainWindow->setCentralWidget(poWidget); poMainWindow->show(); return app.vRun();
}
@
Did anyone find a solution?
-
Had the same problem when starting a new project. For me the problem was with mixing QDeclarativeComponent with QtQuick 2.3. Replacing QDeclarativeComponent by QQuickItem did the trick.
Note: make sure that any includes
@#include <QDeclarativeComponent>@in your code are replaced by
@#include <QQuickItem>@Especially in main.cpp. Including both of these gives compile errors on qmlRegisterType as long as QDeclarativeComponent is included so these two headers should not be mixed. Hope this helps anywone with this problem.
-
Had the same problem when starting a new project. For me the problem was with mixing QDeclarativeComponent with QtQuick 2.3. Replacing QDeclarativeComponent by QQuickItem did the trick.
Note: make sure that any includes
@#include <QDeclarativeComponent>@in your code are replaced by
@#include <QQuickItem>@Especially in main.cpp. Including both of these gives compile errors on qmlRegisterType as long as QDeclarativeComponent is included so these two headers should not be mixed. Hope this helps anywone with this problem.