#include <QtCore>#include <iostream>using namespace std;class MyClass : public QObject{ Q_OBJECT Q_PROPERTY(Priority priority READ priority WRITE setPriority) Q_ENUMS(Priority)public: MyClass(QObject *parent = 0) :QObject(parent) { }; ~MyClass() { cout << "MyClass Destructor"<<endl; }; enum Priority { High, Low, VeryHigh, VeryLow }; void setPriority(Priority priority); Priority priority() const;};int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); MyClass megaInst; return a.exec();}
#include <QtCore>#include <iostream>using namespace std;class MyClass : public QObject{ Q_OBJECT Q_PROPERTY(Priority priority READ priority WRITE setPriority) Q_ENUMS(Priority)public: MyClass(QObject *parent = 0) :QObject(parent) { }; ~MyClass() { cout << "MyClass Destructor"<<endl; }; enum Priority { High, Low, VeryHigh, VeryLow }; void setPriority(Priority priority); Priority priority() const;};int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); MyClass megaInst; return a.exec();}#include "main.moc"
C++ (Qt)#include <QtCore> #include <iostream>using namespace std; class MyClass : public QObject{ Q_OBJECT Q_PROPERTY(Priority priority READ priority WRITE setPriority) Q_ENUMS(Priority) public: MyClass(QObject *parent = 0) :QObject(parent), m_priority( High ) { }; ~MyClass() { cout << "MyClass Destructor"<<endl; }; enum Priority { High, Low, VeryHigh, VeryLow }; void setPriority(Priority priority) { m_priority = prioriry; } Priority priority() const { return m_priority; } private: Priority m_priority;}; int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); MyClass megaInst; return a.exec();} #include "main.moc"