PDA

View Full Version : Error: plugin cannot be loaded for module "QtQuick".



user_mail07
6th November 2013, 19:49
Hi,

I am running my app with open source Qt 5.1.1 using QtQuick2ApplicationViewer on Windows 7. Application builds fine whenever i try to run I get plugin cannot be loaded for module "QtQuick".I feel there is something wrong with qmlRegisterType.

main.qml


import QtQuick 2.0

Item {
width: 800
height: 600

Row {
id: layoutRow

TextButton {
text: "1x1"
onClicked: { workspaceWidget.setLayout(WorkspaceWidget.Layout_1 x1) }
}

TextButton {
text: "2x2"
onClicked: { workspaceWidget.setLayout(WorkspaceWidget.Layout_2 x2) }
}

}

}


main.cpp


#include <QtGui/QGuiApplication>
#include "qtquick2applicationviewer.h"
#include <QQmlContext>
#include <QtQml>
#include "WorkspaceWidget.h"

int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QtQuick2ApplicationViewer viewer;

WorkspaceWidget workspacePane;
viewer.rootContext()->setContextProperty(QLatin1String("workspaceWidget"), &workspacePane);
viewer.setResizeMode(QQuickView::SizeRootObjectToV iew);

qmlRegisterType<WorkspaceWidget>("QtQuick", 2, 0, "WorkspaceWidget");

viewer.setMainQmlFile(QStringLiteral("qml/QtQuick2Demo/main.qml"));
viewer.showExpanded();
return app.exec();
}



I am getting following error in debug pane in Qt Creator


file:///C:/Projects/build-QtQuick2Demo-Desktop_Qt_5_1_1_MSVC2010_32bit-Debug/qml/QtQuick2Demo/main.qml:1:1: plugin cannot be loaded for module "QtQuick": Namespace 'QtQuick' has already been used for type registration
import QtQuick 2.0
^

bounce
12th November 2013, 15:59
it tells you exactly the problem, QtQuick is already taken

qmlRegisterType<WorkspaceWidget>("user_mail07", 2, 0, "WorkspaceWidget");

motaito
25th April 2015, 13:49
You don't really provide a lot of information. Based on what's there the answer has been given already. Generally you need these steps:

1. Create c++ class that contains the Q_OBJECT macro

class WorkspaceWidget
{
Q_OBJECT
public:
// your implementatin goes here...
// whatever function you want to call from qml must be made invokable with the proper macro declaration
Q_INVOKABLE void foo();
}

2. Register the class in main.cpp

qmlRegisterType<WorkspaceWidget>("WorkspaceWidgetNameSpace", 2, 0, "WorkspaceWidgetQml");

// WorkspaceWidget: Your class
// WorkspaceWidgetNameSpace: a namespace that has not yet been used. Can be anything, but must be unique
// WorkspaceWidgetQml: Some name that you give to handle it in a qml file. Can be anything, but must be unique

3. in some qml-file

// import your name space with major and minor version
import WorkspaceWidgetNameSpace 2.0


// declare your class, as qml is a declarative environment
WorkspaceWidgetQml {
id: workspaceWidgetID
}

// do with it what you want
TextButton {
text: "1x1"
onClicked: { workspaceWidgetID.setLayout(WorkspaceWidget.Layout _1x1); }
}