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