AUTO PROPERTIES for Qt
This tool lets you write simple macros like this into your header Qt files:
// QTAUTO_GET_SET_SIGNAL(int, myIntProperty)
The tool, when run, will then add the appropriate get/set/signals to the header file as inline code for your header file. This prevents you from having to manually type things like:
Q_PROPERTY(int myIntProperty READ myIntProperty WRITE setMyIntProperity NOTIFY myIntPropertyChanged);
public:
const int &myIntProperty() const { return m_myIntProperty; }
signals:
void myIntPropertyChanged();
public slots:
void setMyIntProperity(const int &newval) {
if (newval != m_myIntProperty) {
m_myIntProperty = newval;
emit myIntPropertyChanged();
}
}
private:
int m_myIntProperty;
Which is actually what the output produces. though you can customize it by changing the qtauto_properties.h file. But when it replaces it in your file, it’ll be on a single (smashed-together) line.
You can add a line such as:
// QTAUTO_HERE
And the resulting output will be placed below that line.
To make use of it, copy the qtauto_properties.h file into your source directory and then simply run qtautoproperty on the header file and it should modify the header file appropriately. Unless you follow the instructions in the next section, you’ll need to have your macros commented out using // in front of them.
You can set up qtcreator to call the tool automatically for a given file using a setup like this in the Tools->External->Configure settings:
You can make use of inline macros instead of commented out macros, simply include the qtauto_properties.h file into your header file and the macros will no longer trigger compiler errors as they’ll be instantiated as empty defines.
QTAUTO_GET(type, varname) // defines just the varname() function
QTAUTO_GET_SIGNAL(type, varname) // same but all defines a signal
// (but you must emit it!!)
QTAUTO_GET_SET_SIGNAL(type, varname) // defines setVarname() too
// and emits the signal
If you define QTAUTO_DEBUG_SIGNALS_SLOTS and rebuild everything, every time a value is changed in an property a debugging message will be printed (using qDebug()), such as:
setting new value for varName true => false
To turn it on within your .pro file, use this:
DEFINES += QTAUTO_DEBUG_SIGNALS_SLOTS