Qt的Q_CLASSINFO简要分析

新建一个继承于QObject的空白类,如下:

class MyInfo : public QObject
{
    Q_OBJECT
public:
    explicit MyInfo(QObject *parent = nullptr);
 
signals:
 
public slots:
};

然后加上Q_CLASSINFO,如下:

class MyInfo : public QObject
{
    Q_OBJECT
    Q_CLASSINFO("Version", "1.0.0")
    Q_CLASSINFO("Author", "xingzaicpp")
public:
    explicit MyInfo(QObject *parent = nullptr);
 
signals:
 
public slots:
};

对比生成的moc代码:

一对比,一目了然

测试下,如下:

posted @ 2022-09-06 22:14  xingzaicpp  阅读(353)  评论(0编辑  收藏  举报