2011-02-06 78 views
9

我想將Doxygen評論添加到我的Q_PROPERTY中。如何doxygen評論Qt屬性?

例如:

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; } 

我怎麼能告訴Doxygen的那個標題是Qt的元對象系統和title屬性()和setTitle()是訪問函數?我想實現類似的輸出爲this

回答

12

我終於找到了一種方法來做到這一點。

  • 在源文件:

    /** 
    * @brief The name of the user. 
    * @accessors name(), setName() 
    */ 
    Q_PROPERTY(QString name READ name WRITE setName) 
    
  • Doxyfile

    ALIASES = "accessors=\par Accessors:\n" 
    

我所做的就是定義an alias命名爲 「存取」,這將產生一個段落的標題爲「Accessors:」,後面跟着引用的方法。

這裏是什麼樣子的文件中:

enter image description here


提示:如果屬性的名稱是一樣的讀出特性的方法,你可能想在文檔中以'%'開頭(否則訪問者將顯示爲指向自身的鏈接):

/** 
* ... 
* @accessors %name(), setName() 
* ... 
*/ 
2

爲對象名財產qobject.cpp doxygen的註釋開始用 「​​\屬性」 標籤:

/*! 
    \property QObject::objectName 

    \brief the name of this object 

    You can find an object by name (and type) using findChild(). You can 
    find a set of objects with findChildren(). 

    \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 5 

    By default, this property contains an empty string. 

    \sa metaObject(), QMetaObject::className() 
*/ 

您是否嘗試過使用它嗎?如果它不能正常工作,我會試着找出Qt如何生成它的文檔 - 也許你需要在doxygen配置中使用一些宏/別名。

+0

Qt不使用doxygen而使用qdoc來生成它的文檔,但doxygen試圖保持合理的qdoc​​兼容。 – 2014-07-22 21:22:16

12

doxygen支持開箱即用的Qt屬性。只需在屬性聲明之上添加一個文檔註釋,您將在doxygen輸出中看到一個「屬性」。

請注意,如果訪問者函數也有文檔註釋,那麼它們將分開記錄。因此,如果要在生成的文檔中禁用這些訪問器函數,則需要從這些訪問器函數中刪除文檔註釋。