Results 1 to 2 of 2

Thread: Q_DECLARE_OPERATORS_FOR_FLAGS causes breakage in other flags, example source provided

  1. #1
    Join Date
    May 2010
    Posts
    14
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Q_DECLARE_OPERATORS_FOR_FLAGS causes breakage in other flags, example source provided

    When I declare operators for some of my custom flags, it causes some of the default flags to lose their operators. Below is an example that reproduces the issue (Qt 4.6/4.7).

    Not sure if I've simply missed some caveat and, of course, in my actual app the MainWindow and Foo classes are in separate files as is the main().

    Qt Code:
    1. #include <QList>
    2. #include <QSet>
    3. #include <iostream>
    4. #include <cstdlib>
    5. #include <ctime>
    6. #include <QObject>
    7. #include <QDockWidget>
    8. #include <QMainWindow>
    9.  
    10. using namespace std;
    11.  
    12. namespace kex
    13. {
    14. class Foo
    15. {
    16. Q_FLAGS(NType NTypes)
    17.  
    18. public:
    19. enum NType {
    20. TypeOne = 0x1,
    21. TypeTwo = 0x2,
    22. };
    23. Q_DECLARE_FLAGS(NTypes, NType)
    24.  
    25. void flagsFunc(NTypes nt)
    26. {
    27.  
    28. }
    29. };
    30.  
    31. Q_DECLARE_OPERATORS_FOR_FLAGS(Foo::NTypes)
    32.  
    33. class MyMainWindow : public QMainWindow
    34. {
    35. public:
    36. MyMainWindow(QWidget *parent = 0) : QMainWindow(parent) {
    37. /*
    38. temp.cpp: In constructor 'kex::MyMainWindow::MyMainWindow(QWidget*)':
    39. temp.cpp:38: error: conversion from 'int' to 'Qt::DockWidgetAreas' is ambiguous
    40. /Library/Frameworks/QtCore.framework/Headers/qglobal.h:2169: note: candidates are: QFlags<Enum>::QFlags(void**) [with Enum = Qt::DockWidgetArea] <near match>
    41. /Library/Frameworks/QtCore.framework/Headers/qglobal.h:2168: note: QFlags<Enum>::QFlags(Enum) [with Enum = Qt::DockWidgetArea] <near match>
    42.   */
    43. _dock.setAllowedAreas(Qt::LeftDockWidgetArea |
    44. Qt::RightDockWidgetArea);
    45. }
    46.  
    47. private:
    48. QDockWidget _dock;
    49. };
    50.  
    51. };
    52.  
    53. int main ()
    54. {
    55. kex::Foo foo;
    56. foo.flagsFunc(kex::Foo::TypeOne | kex::Foo::TypeTwo);
    57. return 0
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    May 2010
    Posts
    14
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Q_DECLARE_OPERATORS_FOR_FLAGS causes breakage in other flags, example source prov

    Due to the nature of namspace lookups of operators, Q_DECLARE_OPERATORS_FOR_FLAGS must be declared globally.

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

    juannm (7th March 2016)

Similar Threads

  1. Does QDataWidgetMapper use flags?
    By Netwiz in forum Qt Programming
    Replies: 1
    Last Post: 29th October 2021, 00:56
  2. Replies: 2
    Last Post: 25th April 2009, 08:50
  3. Is flags a typdef?
    By chuckle in forum Qt Programming
    Replies: 1
    Last Post: 13th September 2007, 22:26
  4. Flags not doing the work
    By chaosgeorge in forum Qt Programming
    Replies: 1
    Last Post: 23rd November 2006, 23:35
  5. How to find size provided by QScrollView
    By Sarma in forum Qt Programming
    Replies: 1
    Last Post: 7th March 2006, 09:26

Tags for this Thread

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.