Skip to content

Instantly share code, notes, and snippets.

@eswizardry
Forked from Rolias/PropertyHelper.h
Created May 17, 2018 19:10
Show Gist options
  • Select an option

  • Save eswizardry/c33a35c9c1124ed28ee50ed3763a7668 to your computer and use it in GitHub Desktop.

Select an option

Save eswizardry/c33a35c9c1124ed28ee50ed3763a7668 to your computer and use it in GitHub Desktop.
Qt Auto Property Macros
#pragma once
#include <QObject>
//See Gist Comment for description, usage, warnings and license information
#define AUTO_PROPERTY(TYPE, NAME) \
Q_PROPERTY(TYPE NAME READ NAME WRITE NAME NOTIFY NAME ## Changed ) \
public: \
TYPE NAME() const { return a_ ## NAME ; } \
void NAME(TYPE value) { \
if (a_ ## NAME == value) return; \
a_ ## NAME = value; \
emit NAME ## Changed(value); \
} \
Q_SIGNAL void NAME ## Changed(TYPE value);\
private: \
TYPE a_ ## NAME;
#define READONLY_PROPERTY(TYPE, NAME) \
Q_PROPERTY(TYPE NAME READ NAME CONSTANT ) \
public: \
TYPE NAME() const { return a_ ## NAME ; } \
private: \
void NAME(TYPE value) {a_ ## NAME = value; } \
TYPE a_ ## NAME;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment