Results 1 to 6 of 6

Thread: Opposite of |= operation

  1. #1
    Join Date
    Aug 2008
    Posts
    132
    Thanks
    23
    Thanked 3 Times in 3 Posts

    Default Opposite of |= operation

    Hi

    This is probably a simple question, but I can't figure out how to do it. I have a bitwise enum. I know that you set one of the bits as follows (example taken out of a table model implementation:

    Qt Code:
    1. if (is_editable)
    2. item_flags |= Qt::ItemIsEditable;
    3. //else
    4. // item_flags (what to do here) Qt::ItemIsEditable;
    To copy to clipboard, switch view to plain text mode 

    I've searched the web but couldn't find any solutions, or I missed them.
    I looked at the QWidget::setAttribute() function implementation but it does quite a few things in there and I'm hoping there is a simpler way to do it.

    Thanks for your time.
    Jaco

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Opposite of |= operation

    Do nothing in else.

  3. #3
    Join Date
    Aug 2008
    Posts
    132
    Thanks
    23
    Thanked 3 Times in 3 Posts

    Default Re: Opposite of |= operation

    I agree but it will only work in the following scenario won't it:

    Qt Code:
    1. item_flags = 0;
    2.  
    3. if (is_editable)
    4. item_flags |= Qt::ItemIsEditable;
    5. //else
    6. // item_flags (what to do here) Qt::ItemIsEditable;
    To copy to clipboard, switch view to plain text mode 

    I need to be able to remove that flag is it was set, for example:

    Qt Code:
    1. item_flags = Qt::ItemIsEditable;
    2.  
    3. if (is_editable)
    4. item_flags |= Qt::ItemIsEditable;
    5. //else
    6. // item_flags (what to do here) Qt::ItemIsEditable;
    To copy to clipboard, switch view to plain text mode 

    Any ideas?
    Thanks
    Jaco

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Opposite of |= operation

    item_flags &= ~Qt::ItemIsEditable;

  5. The following user says thank you to squidge for this useful post:

    JPNaude (16th November 2009)

  6. #5
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Opposite of |= operation

    Quote Originally Posted by JPNaude View Post
    I need to be able to remove that flag is it was set, for example:
    This is called bit masking.
    To unset a flag (zero-out a bit or set a bit to zero) flags & ~flagbitN.
    Enjoy

  7. The following user says thank you to yogeshgokul for this useful post:

    JPNaude (16th November 2009)

  8. #6
    Join Date
    Aug 2008
    Posts
    132
    Thanks
    23
    Thanked 3 Times in 3 Posts

    Default Re: Opposite of |= operation

    Brilliant! Thank you will give it a go.

Similar Threads

  1. C++ Tree View operation
    By zeeb100 in forum Qt Programming
    Replies: 9
    Last Post: 18th February 2009, 17:09
  2. rotate operation and cpu usage
    By ersin.ozkan in forum Qt Programming
    Replies: 2
    Last Post: 30th December 2008, 06:42
  3. About File write operation
    By raghvendramisra in forum Qt Programming
    Replies: 1
    Last Post: 17th April 2008, 11:41
  4. setting Cursor for one operation
    By keshab in forum Newbie
    Replies: 1
    Last Post: 22nd December 2006, 08:09
  5. Problem in Cut Operation
    By ankurjain in forum Qt Programming
    Replies: 4
    Last Post: 14th April 2006, 12:23

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
  •  
Qt is a trademark of The Qt Company.