Results 1 to 2 of 2

Thread: Counting flags in a bit mask

  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Counting flags in a bit mask

    Hi,

    I am using a enum as a bit mask. I also use Q_DECLARE_FLAGS. Now I have the need to know how many flags are set, but I can't find a simple solution for that: will say no build in function. For now I use a simple loop which counts the flags. Just wondering if there is a "standard"/better way without a self defined function...


    Thanks

    QFlags::cont() would have been nice

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Counting flags in a bit mask

    Flags don't have to be exclusive, so any count() wouldn't work.

    Here you go for some algorithms: http://graphics.stanford.edu/~seande...ntBitsSetNaive
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QLineEdit and input mask
    By tpf80 in forum Qt Programming
    Replies: 7
    Last Post: 9th May 2014, 19:47
  2. Replies: 5
    Last Post: 10th July 2009, 12:11
  3. input mask problem
    By zgulser in forum Qt Programming
    Replies: 10
    Last Post: 8th May 2009, 14:11

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.