Right now I have a header file called enums.h as such:
enums.h
#ifndef ENUMS_H
#define ENUMS_H
#include <Qt>
enum paper_orient{portrait, landscape};
enum ruler_orient{top_ruler, bottom_ruler, left_ruler, right_ruler};
enum relationships_type{line_item, other};
enum settings_type{line_object, plot, text};
#endif // ENUMS_H
#ifndef ENUMS_H
#define ENUMS_H
#include <Qt>
enum paper_orient{portrait, landscape};
enum ruler_orient{top_ruler, bottom_ruler, left_ruler, right_ruler};
enum relationships_type{line_item, other};
enum settings_type{line_object, plot, text};
#endif // ENUMS_H
To copy to clipboard, switch view to plain text mode
With this setup, wherever I want to use these enums, I just #include "enums.h" and they are available.
In learning to do things the Qt way, it appears that QMetaEnum would be a more streamlined approach.
In the docs, I find this example:
{
Q_OBJECT
Q_ENUMS(Priority)
public:
~MyClass();
enum Priority { High, Low, VeryHigh, VeryLow };
void setPriority(Priority priority);
Priority priority() const;
};
class MyClass : public QObject
{
Q_OBJECT
Q_ENUMS(Priority)
public:
MyClass(QObject *parent = 0);
~MyClass();
enum Priority { High, Low, VeryHigh, VeryLow };
void setPriority(Priority priority);
Priority priority() const;
};
To copy to clipboard, switch view to plain text mode
If I use this approach, does this mean that the Priority enum is only available within MyClass? What if I wish to use this enum in other classes? Ultimately that is what I would like to establish, is a series of global enums that are available anywhere in my project.
Bookmarks