Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-34057

undefined value of enum in derived class

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • Not Evaluated
    • None
    • 4.7.4, 4.8.5
    • Build System
    • None

    Description

      Base class:

      human.h
      #include <QObject>
      
      class Human : public QObject
      {
          Q_OBJECT
          Q_ENUMS(Gender)
      
      public:
          Human() : QObject() {}
      
          enum Gender {
              Male,
              Female
          };
      };
      

      Derived class

      female.h
      #include "human.h"
      
      class Female : public Human
      {
          // Q_OBJECT compile error!
          Q_ENUMS(Brain)
      public:
          enum Brain {
              Smart,
              Stupid
          };
      
          Female() : Human() {}
      };
      

      Type registration and qml viewer run:

      main.cpp
      #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();
      }
      
      

      call scope

      main.qml
      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
          }
      }
      

      update:
      adding Q_OBJECT to derived class give me compile (linking) error.

      After asking some people, I delete build folder with make files and build again. Problem gone.

      So I think this problem related with QtCreator or general qt build system (it's repeated in test project too).

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              aalpert Alan Alpert
              null NullPointerException
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes