Reputation:
I am sorry to ask a question with such a "meaningful" title, but I just can't get what the compiler is complaining about, the code was working fine just moments ago, I added an extra method and everything broke. Removing the last changes did not fix it.
class NodeWrapper : public QObject {
Q_OBJECT
Q_ENUMS(NodeType NodeStatus)
Q_PROPERTY(NodeType type READ type WRITE setType NOTIFY typeChanged)
Q_PROPERTY(QString typeString READ typeString NOTIFY typeChanged)
Q_PROPERTY(NodeStatus status READ status WRITE setStatus NOTIFY statusChanged)
public:
NodeWrapper(QObject * parent = 0) : QObject(parent) { }
enum NodeType {
T_NODE,
T_FOLDER
};
enum NodeStatus {
S_OK,
S_WARNING,
S_ERROR
};
// type
inline NodeType type() { return _type; }
inline QString typeString() { return metaObject()->enumerator(0).key(type()); }
inline void setType(NodeType v) {
if (_type != v) {
_type = v;
emit typeChanged();
}
}
// status
inline NodeStatus status() { return _node.getStatus(); }
inline void setStatus(NodeStatus v) {
if (_node.getStatus() != v) {
_node.setStatus(v);
emit statusChanged();
}
}
signals:
void typeChanged();
void statusChanged();
private:
NodeType _type;
Node _node;
};
The errors begin at the S_OK
member of the NodeStatus
enum:
error: expected identifier before '(' token
S_OK,
^
error: expected '}' before '(' token
error: expected ')' before numeric constant
S_OK,
^
error: 'NodeType' does not name a type
inline NodeType type() { return _type; }
^
error: 'metaObject' was not declared in this scope
inline QString typeString() { return metaObject()->enumerator(0).key(type()); }
^
error: 'type' was not declared in this scope
inline QString typeString() { return metaObject()->enumerator(0).key(type()); }
^
...
Upvotes: 0
Views: 293
Reputation: 24576
If you google for S_OK define
, you'll find that in some windows header it is defined as (HRESULT)0x00000000
- which explains the compiler complaining about parens and numeric constants.
What you can do to get rid of that error:
S_
prefix or use another prefix.The latter is more likely to work, as you will come across WinAPI headers often times. Maybe even QT exposes your classes to them, and as S_OK
is an evil #define
, you have little chance to fight it.
Upvotes: 1
Reputation: 7960
S_OK is defined as an HRESULT of zero (winerror.h). Try another prefix such as NS_OK or nsOK.
Upvotes: 2
Reputation: 4455
At a guess you've inadvertently included <windows.h>
before this definition, which redefines S_OK as a number through #define and thus causing a compile error in the enumeration. This type of clutter in the global namespace is an unfortunate consequence of C compatibility, and in practice the safest bet is to just rename the field (S_SUCCESS perhaps?)
Upvotes: 7