Results 1 to 2 of 2

Thread: QFlags with std::initializer_list

  1. #1
    Join Date
    Nov 2009
    Location
    US, Midwest
    Posts
    215
    Thanks
    62
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QFlags with std::initializer_list

    I am having a problem with QFlags class. Here is an pseudo-code example. I'll appreciate any comment/advise. Thanks.

    Qt Code:
    1. class A {
    2. ...
    3. public:
    4. enum class SignalState {ENTRY, EXIT};
    5. ...
    6. };
    7.  
    8. class B {
    9. public:
    10. Q_DECLARE_FLAGS(SignalUsage, A::SignalState)
    11. B () : usage(A::SignalState::ENTRY | A::SignalState::EXIT) // fails
    12. {
    13. }
    14. B (int) : usage(std::initializer_list<SignalUsage>({A::SignalState::ENTRY, A::SignalState::EXIT}) // fails
    15. {
    16. }
    17. B (char) : usage(A::SignalState::ENTRY) // compiles
    18. {
    19. usage |= A::SignalState::EXIT; // compiles
    20. }
    21. private:
    22. SignalUsage usage;
    23. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QFlags with std::initializer_list

    Try removing the "class" scoping on your definition of SignalState. It is possible that the Q_DECLARE_FLAGS() macro is not generating the correct code for this level of C++11 compliance. You can simulate scoping the old-fashioned way: SS_ENTRY, SS_EXIT.

  3. The following user says thank you to d_stranz for this useful post:

    TorAn (18th January 2016)

Similar Threads

  1. Use QFlags
    By qt_developer in forum Newbie
    Replies: 3
    Last Post: 25th May 2012, 11:35
  2. Replies: 5
    Last Post: 18th July 2010, 08:39
  3. QFlags questions
    By elcuco in forum Newbie
    Replies: 3
    Last Post: 19th March 2010, 14:33
  4. Storing and Retrieving a QFlags
    By darkadept in forum Qt Programming
    Replies: 3
    Last Post: 4th October 2007, 18:53

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.