Menu

Not found Enum from QObject derived class

Help
kwisp
2015-05-04
2015-05-04
  • kwisp

    kwisp - 2015-05-04

    Hello.

    1. Create QObject derived class with enum. Register enum in meta object system.
    #include "QObject"
    class CQEnumWrapper : public QObject
    {     
        Q_OBJECT
        Q_ENUMS(SomeEnum)        
    public:
        enum SomeEnum {seA, seB, seC, seD};
        CQEnumWrapper(QObject* parent = 0);
    };
    
    1. Create decorator
    #include "cqenumwrapper.h"
    class PyWrapper : public QObject
    {     
        Q_OBJECT
    public:
        PyWrapper() {}
        ~PyWrapper() {}                
    public slots:
        CQEnumWrapper* new_CQEnumWrapper(QObject* parent = 0 )
        {
            return new CQEnumWrapper(parent);
        }
    };
    
    1. Add Decorator and register metaClass
    PythonQt::self()->addDecorators(new PyWrapper());
    PythonQt::self()->registerClass(&CQEnumWrapper::staticMetaObject, "myObjects");
    
    1. Call in python script
    dir(myObjects.CQEnumWrapper)

    Out:

    enum SomeEnum not found on CQEnumWrapper
    enum SomeEnum not found on CQEnumWrapper
    enum SomeEnum not found on CQEnumWrapper
    enum SomeEnum not found on CQEnumWrapper
    

    How can I wrapp enum from QObject derived class in PythonQt?
    What wrong with my code?

    Linux klochkov 3.13.0-49-generic #81-Ubuntu SMP Tue Mar 24 19:29:15 UTC 2015
    

    i686 i686 i686 GNU/Linux

    QMake version 2.01a
    Using Qt version 4.8.6 in /usr/lib/i386-linux-gnu
    
    PythonQt version 3.0
    

    Thanks.

     
  • Florian Link

    Florian Link - 2015-05-04

    I think this is an ordering problem, try to register the class before adding the decorator.

     
  • kwisp

    kwisp - 2015-05-04

    Thanks, Florian. It is quite so. My code works now.

    I think that in 'PythonQt3.0/examples/PyDecoratorsExample' we need to register the classes before adding the decorator too.

     

Log in to post a comment.