Skip to content

automatic tools for creating and maintaining properties and access functions for qt applications

License

Notifications You must be signed in to change notification settings

hardaker/qtautoproperty

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AUTO PROPERTIES for Qt

What qtautoproperty does

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.

Options

You can add a line such as:

// QTAUTO_HERE

And the resulting output will be placed below that line.

Usage

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:

./images/examplesettings.png

link to image

Using inline macros instead of commented macros

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.

Available Macros

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

Turning on extra debugging output

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

About

automatic tools for creating and maintaining properties and access functions for qt applications

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published