miqqo
7th July 2010, 21:50
Hi everyone, is there anybody who can help me with follwoing problem? I would like to use QFlags class. When compiling below code i get error.
#ifndef OBJECTQ_H
#define OBJECTQ_H
#include <QtCore/qglobal.h>
#include <QtCore/qobject.h>
class Objectq : public QObject
{
public:
enum MyEnum
{
Enum1 = 0x0,
Enum2 = 0x1
};
Q_DECLARE_FLAGS(MyEnums, MyEnum)
Objectq();
MyEnums flags() const;
private:
MyEnums mFlags;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(Objectq::MyEnums);
#endif // OBJECTQ_H
The compiler output is following:
..\Flagi\objectq.cpp(7) : error C2143: syntax error : missing ';' before 'Objectq::flags'
..\Flagi\objectq.cpp(7) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
..\Flagi\objectq.cpp(8) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
..\Flagi\objectq.cpp(8) : error C2556: 'int Objectq::flags(void) const' : overloaded function differs only by return type from 'Objectq::MyEnums Objectq::flags(void) const'
c:\users\lukasz\workspace\flagi\objectq.h(17) : see declaration of 'Objectq::flags'
..\Flagi\objectq.cpp(8) : error C2371: 'Objectq::flags' : redefinition; different basic types
c:\users\lukasz\workspace\flagi\objectq.h(17) : see declaration of 'Objectq::flags'
It seems that in method MyEnums flags() const; type MyEnums isn't visible, but I don't have idea why. According to QT documentation macro Q_DECLARE_FLAGS should do the job, but it isn't. I've spent a lot of time trying to get known what's is wrong, now it's time to ask for help somone clever than me ;).
#ifndef OBJECTQ_H
#define OBJECTQ_H
#include <QtCore/qglobal.h>
#include <QtCore/qobject.h>
class Objectq : public QObject
{
public:
enum MyEnum
{
Enum1 = 0x0,
Enum2 = 0x1
};
Q_DECLARE_FLAGS(MyEnums, MyEnum)
Objectq();
MyEnums flags() const;
private:
MyEnums mFlags;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(Objectq::MyEnums);
#endif // OBJECTQ_H
The compiler output is following:
..\Flagi\objectq.cpp(7) : error C2143: syntax error : missing ';' before 'Objectq::flags'
..\Flagi\objectq.cpp(7) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
..\Flagi\objectq.cpp(8) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
..\Flagi\objectq.cpp(8) : error C2556: 'int Objectq::flags(void) const' : overloaded function differs only by return type from 'Objectq::MyEnums Objectq::flags(void) const'
c:\users\lukasz\workspace\flagi\objectq.h(17) : see declaration of 'Objectq::flags'
..\Flagi\objectq.cpp(8) : error C2371: 'Objectq::flags' : redefinition; different basic types
c:\users\lukasz\workspace\flagi\objectq.h(17) : see declaration of 'Objectq::flags'
It seems that in method MyEnums flags() const; type MyEnums isn't visible, but I don't have idea why. According to QT documentation macro Q_DECLARE_FLAGS should do the job, but it isn't. I've spent a lot of time trying to get known what's is wrong, now it's time to ask for help somone clever than me ;).