I would like to attach Doxygen comments to my Q_PROPERTYs.
For example:
song.h
class Song : public QObject
{
Q_OBJECT
private:
Q_PROPERTY(QString title READ title WRITE setTitle);
QString _title;
public:
QString title() const;
void setTitle(const QString& value);
};
song.cpp
#include "song.h"
Song::Song(QObject *parent) :
QObject(parent)
{
}
QString Song::title() const { return _title; }
void Song::setTitle(const QString &value) { _title = value; }
How can I tell Doxygen that title is a property in the Qt Meta-Object system and title() and setTitle() are the accessor functions? I would like to achieve a similar output to this.
Once specified, you can generate the comment stub by typing the respective “///” or “/**” above a function, or by using the (Ctrl+/) shortcut.
Doxygen allows you to put your documentation blocks practically anywhere (the exception is inside the body of a function or inside a normal C style comment block).
Doxygen is the de facto standard tool for generating documentation from annotated C++ sources, but it also supports other popular programming languages such as C, Objective-C, C#, PHP, Java, Python, IDL (Corba, Microsoft, and UNO/OpenOffice flavors), Fortran, and to some extent D.
I have finally found a way to do this.
In the source files:
/**
* @brief The name of the user.
* @accessors name(), setName()
*/
Q_PROPERTY(QString name READ name WRITE setName)
In the Doxyfile
:
ALIASES = "accessors=\par Accessors:\n"
What I've done is define an alias named "accessors" that will generate a paragraph with the title "Accessors:" followed by the referenced methods.
Here's what it looks like in the documentation:
Tip: if the name of the property is the same as the method for reading the property, you may want to precede the accessor's name in the documentation by a '%
' (otherwise the accessor will be displayed as a link that points to itself):
/**
* ...
* @accessors %name(), setName()
* ...
*/
doxygen supports Qt properties out of the box. Just add a documentation comment above the property declaration, and you will see a "property" in the doxygen output.
Please note, that the accessor functions will be documented separately, if they also have documentation comments. You therefore need to remove documentation comments from these accessor functions, if you want to suppress these in the generated documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With