Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to doxygen comment Qt properties?

Tags:

c++

qt

doxygen

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.

like image 304
Tamás Szelei Avatar asked Feb 06 '11 15:02

Tamás Szelei


People also ask

How do you comment on Doxygen?

Once specified, you can generate the comment stub by typing the respective “///” or “/**” above a function, or by using the (Ctrl+/) shortcut.

Where do doxygen comments go?

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).

What is Doxygen C++?

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.


2 Answers

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:

enter image description here


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()
 * ...
 */
like image 178
Nathan Osman Avatar answered Oct 21 '22 03:10

Nathan Osman


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.

like image 29
lunaryorn Avatar answered Oct 21 '22 04:10

lunaryorn