Что-то в qml с наследованием не то.
Базовый класс:
#include <QObject>
class Human : public QObject
{
Q_OBJECT
Q_ENUMS(Gender)
public:
Human() : QObject() {}
enum Gender {
Male,
Female
};
};
Дочерний класс:
#include "human.h"
class Female : public Human
{
Q_ENUMS(Brain)
public:
enum Brain {
Smart,
Stupid
};
Female() : Human() {}
};
#include <QApplication>
#include "qmlapplicationviewer.h"
#include "female.h"
#include <qdeclarative.h>
Q_DECL_EXPORT int main(int argc, char *argv[])
{
QScopedPointer<QApplication> app(createApplication(argc, argv));
qmlRegisterType<Female>("factory.inc.models", 1, 0, "Female");
QmlApplicationViewer viewer;
viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
viewer.setMainQmlFile(QLatin1String("qml/test/main.qml"));
viewer.showExpanded();
return app->exec();
}
Место использования
import QtQuick 1.0
import factory.inc.models 1.0
Rectangle {
width: 360
height: 360
Component.onCompleted: {
console.log(Female.Male); // 0
console.log(Female.Female); // 1
console.log(Female.Smart); // undefined
console.log(Female.Stupid); // undefined
}
}
Почему же undefined?