Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

Registering enum in QML: does not work in QtQuick2

$
0
0
Hi I’m porting an application from Quick1 to Quick2, and got problems with registering an enum. I have the following which works with Quick1: keyboardcontrol.h #include <QObject>   class iDrive:public QObject {     Q_OBJECT     Q_ENUMS(iDriveCommands) public:       enum iDriveCommands     {         IUndef = 0,         IUp,         IRight,         IDown,         ILeft,         IPush,         IRotLeft,         IRotRight     }; }; This was registered in the main.cpp: #include <QApplication> #include "qmlapplicationviewer.h" #include <QDeclarativeComponent> #include <QDeclarativeEngine> #include <QDeclarativeContext> #include "keyboardcontrol.h"   Q_DECL_EXPORT int main(int argc, char *argv[]) {       QScopedPointer<QApplication> app(createApplication(argc, argv));      QmlApplicationViewer viewer;       qmlRegisterType<iDrive>("iDriveLib", 1, 0,"iDrive"); ..... } and was used in the qml: import QtQuick 1.1 import iDriveLib 1.0   Rectangle {    id: mainWindow     width: 800     height: 480       function keyEventHandling( key) //Is called from somewhere, not important for this problem     {         switch (key)         {             case iDrive.IUp:             {                 console.log("Up");                 break;             }     } } When working with Quick1, this works and I will run in the case iDrive.IUp For porting it into Quick2, I changed only the main.cpp #include <QtGui/QGuiApplication> #include "qtquick2applicationviewer.h" #include <QtQuick/QQuickPaintedItem> #include <QSurface> #include <QSurfaceFormat> #include "keyboardcontrol.h"     int main(int argc, char *argv[]) {     QGuiApplication app(argc, argv);     QtQuick2ApplicationViewer viewer;       qmlRegisterType<iDrive>("iDriveLib", 1, 0,"iDrive");   } When running this, I got the following error: ReferenceError: iDrive is not defined What did I miss?

Viewing all articles
Browse latest Browse all 4972

Trending Articles