Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. [SOLVED]How to cast enums which are using QFlags and QList?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved C++ Gurus
5 Posts 3 Posters 4.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    terietor
    wrote on last edited by
    #1

    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

    terietor.gr

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

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

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • T Offline
        T Offline
        terietor
        wrote on last edited by
        #3

        [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.

        terietor.gr

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            @
            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;
            }
            @

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved