Results 1 to 3 of 3

Thread: How to use Q_FLAGS with bitwise operations in QML?

  1. #1
    Join Date
    Mar 2013
    Posts
    18
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows Android

    Default Re: How to use Q_FLAGS with bitwise operations in QML?

    Hello,

    I have to expose a Q_FLAGS to qml and I would like to use it with bitwise operations e.g.:

    Qt Code:
    1. //Some.qml
    2.  
    3. if(result.directions & FlickResult.LEFT)
    4. {
    5. slider.value-=0.5
    6. }
    7.  
    8. if(result.directions & FlickResult.RIGHT)
    9. {
    10. slider.value+=0.5
    11. }
    To copy to clipboard, switch view to plain text mode 
    On C++ side everything is fine but on QML side I just receive a QVariant(Flick:irections)) as value for "result.directions". It seems that the encapsulated value cannot be used with bitwise operations.

    Does anyone how Q_FLAGS can be used with bitwise operations in QML?


    Added after 1 34 minutes:


    I have found a workaround for my problem.

    Instead of trying to expose the Q_Flag type I exposed an integer instead.
    I converted the q_flag to int like this

    Qt Code:
    1. int FlickGestureResult::getDirections() const
    2. {
    3. return int(m_gestureDirections);
    4. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Clever&Smart; 17th March 2016 at 10:27.

  2. #2
    Join Date
    Mar 2013
    Posts
    18
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows Android

    Default Re: How to use Q_FLAGS with bitwise operations in QML?

    Finally I got it

    The problem was caused by my enum declaration and a mixed up macro usage:

    Qt Code:
    1. enum class GestureState
    2. {
    3. NoGesture,
    4. GestureStarted,
    5. GestureUpdated,
    6. GestureFinished,
    7. };
    8. Q_ENUMS(GestureState)//mixed up, has to be Q_ENUM (without s) for Qt >= 5.5
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. typedef enum
    2. {
    3. NoGesture,
    4. GestureStarted,
    5. GestureUpdated,
    6. GestureFinished,
    7. }GestureState;
    8. Q_ENUMS(GestureState) //ok with this enum and Qt <5.5
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to use Q_FLAGS with bitwise operations in QML?

    The second should be ok for all Qt5, the difference to the above is that this is a classic enum and the other is a C++11 enum class.

    Cheers,
    _

Similar Threads

  1. Replies: 1
    Last Post: 5th March 2012, 08:38
  2. In which thread are TCP IO-Operations done?
    By P@u1 in forum Qt Programming
    Replies: 9
    Last Post: 21st June 2011, 13:02
  3. Bitwise shifting and ORing HexaDecimal Value
    By nagabathula in forum Qt Programming
    Replies: 14
    Last Post: 19th November 2010, 07:22
  4. Bit operations
    By Lykurg in forum General Programming
    Replies: 1
    Last Post: 8th April 2010, 11:11
  5. Graphics operations - Qt 4.1
    By hoborg in forum Newbie
    Replies: 1
    Last Post: 18th February 2006, 14:09

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.