QFlags Enum Type Conversion not working suddenly

This code works for me quite a while in the library:

MyClass::MyClass() 
  : QDialog()
{
    // (...)
    setWindowFlags( Qt::CustomizeWindowHint | Qt::WindowTitleHint );
    // (...)
}

Then, after changing various parts of the library, I get this message all of a sudden:

error C2664: 'QWidget::setWindowFlags': cannot convert parameter 1 from 'int' to 'Qt::WindowFlags'

Apparently he does not find | operator overloading provided by the QFlags class, so the result | returns an int, not a QFlags construct.

I know that I could manually pass the result in (Qt::WindowFlags)and make it work, but QFlags usually make this kind of unnecessary.

Any idea what change could lead to this behavior?

I include <QtGui/QDialog>, which will usually suffice. Inclusion <QtCore/QFlags>does not change behavior.

+5
source share
3 answers

5.12.0, : " | Qt QFlags ". 5.12.0 Qt (. Qnamespace.h), Qt.

, , , . , , Qt . ADL , , , , .

Qt , , , 5.12.0. , :

using ::operator|;
setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint);

, , , .

+5

, , Q_DECLARE_OPERATORS_FOR_FLAGS, - , .

@isanae, If there is another operator that matches in the current namespace, .... , .

, Q_DECLARE_OPERATORS_FOR_FLAGS , , Qt.

, . , , , , , : Q_DECLARE_OPERATORS_FOR_FLAGS .

+1

You tried to separate | expression from function call? Sort of:

// ..
Qt::WindowFlags flags = Qt::CustomizeWindowHint | Qt::WindowTitleHint;
setWindowFlags( flags );
// ...

Just to find out exactly where the problem is ...

If this is an inclusion problem, just #include <QtGui>

0
source

All Articles