[SOLVED]How to cast enums which are using QFlags and QList?



  • Hello,

    I want to create a wrapper,because the original class doesn't derive from QObject.
    I don't have the option to make the original class to derive from QObject.

    This is my code,

    @class WrapLocale :public QObject {
    Q_OBJECT
    public:
    ...
    enum ENUMList {
    value1
    ...
    };

    enum ENUMFlags {
    content
    ...
    };
    
    Q_DECLARE_FLAGS(ENUMFlag, ENUMFlags)
    
    ENUMFlag giveMeFlags();
    

    private:
    Locale *m_locale
    };

    class Locale {
    public:
    ...
    enum ENUMList {
    value1
    ...
    };

    QList<Locale::EnumList> list();
    
    enum ENUMFlags {
    content
    ...
    };
    
    Q_DECLARE_FLAGS(ENUMFlag, ENUMFlags)
    ENUMFlag giveMeFlags();
    

    };

    QListWrapLocale::EnumList WrapLocale::something()
    {
    return m_locale->list();//error!
    //how can I cast it?
    }

    ENUMFlag WrapLocale::giveMeFlags()
    {
    return m_locale->giveMeFlags();//error!
    //how can I cast it??
    }@

    I can't cast the methods because the first one is using QList and the second
    one is using the Q_DECLARE_FLAGS.

    thanks in advance



  • You should define your enums only at one place and just use it in the other one.



  • [quote author="Volker" date="1327669643"]You should define your enums only at one place and just use it in the other one.
    [/quote]

    I can't.
    I am writing a wrapper,and inside my wrapper i use Q_ENUMS.
    If I am correct Q_ENUMS depends on the QDeclarative module. If so, the policy of the specific project
    forbids to add such a dep in the original code.



  • No, Q_ENUMS do not depend on QDeclarative. They are in QtCore.



  • @
    class Locale {
    public:
    enum ENUMList { ... };
    enum ENUMFlags { ... };

    Q_DECLARE_FLAGS(ENUMFlag, ENUMFlags)
    
    QList<Locale::EnumList> list();
    ENUMFlag giveMeFlags();
    

    };

    class WrapLocale {
    public
    QListLocale::EnumList returnList() {
    return m_locale.list();
    }

    Locale::ENUMFlag returnFlags() {
        return m_locale.giveMeFlags();
    }
    

    private:
    Locale m_locale;
    }
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.