Skip to content

Commit de935e4

Browse files
committed
QClassInfo
1 parent edbaa8f commit de935e4

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed

6-6-QClassINFO/6-6-QClassINFO.pro

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
QT -= gui
2+
3+
CONFIG += c++11 console
4+
CONFIG -= app_bundle
5+
6+
# The following define makes your compiler emit warnings if you use
7+
# any Qt feature that has been marked deprecated (the exact warnings
8+
# depend on your compiler). Please consult the documentation of the
9+
# deprecated API in order to know how to port your code away from it.
10+
DEFINES += QT_DEPRECATED_WARNINGS
11+
12+
# You can also make your code fail to compile if it uses deprecated APIs.
13+
# In order to do so, uncomment the following line.
14+
# You can also select to disable deprecated APIs only up to a certain version of Qt.
15+
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
16+
17+
SOURCES += \
18+
main.cpp \
19+
test.cpp
20+
21+
# Default rules for deployment.
22+
qnx: target.path = /tmp/$${TARGET}/bin
23+
else: unix:!android: target.path = /opt/$${TARGET}/bin
24+
!isEmpty(target.path): INSTALLS += target
25+
26+
HEADERS += \
27+
test.h

6-6-QClassINFO/main.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <QCoreApplication>
2+
#include <QDebug>
3+
#include <QMetaObject>
4+
#include <QMetaProperty>
5+
#include <QMetaClassInfo>
6+
#include <QMetaMethod>
7+
#include <QVariant>
8+
#include "test.h"
9+
10+
11+
void listClassInfo(QObject *obj) {
12+
qInfo() << obj->metaObject()->className();
13+
for(int i = 0; i < obj->metaObject()->classInfoCount(); i++) {
14+
QMetaClassInfo c = obj->metaObject()->classInfo(i);
15+
qInfo() << "Property: " << c.name() << " = " << c.value();
16+
}
17+
}
18+
19+
int main(int argc, char *argv[])
20+
{
21+
QCoreApplication a(argc, argv);
22+
23+
test t;
24+
listClassInfo(&t);
25+
26+
return a.exec();
27+
}

6-6-QClassINFO/test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "test.h"
2+
3+
test::test(QObject *parent) : QObject(parent)
4+
{
5+
6+
}

6-6-QClassINFO/test.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef TEST_H
2+
#define TEST_H
3+
4+
#include <QObject>
5+
6+
class test : public QObject
7+
{
8+
Q_OBJECT
9+
Q_CLASSINFO("Author", "Bryan Cairns")
10+
Q_CLASSINFO("Url", "http://www.voidrealms.com")
11+
12+
public:
13+
explicit test(QObject *parent = nullptr);
14+
15+
signals:
16+
17+
public slots:
18+
};
19+
20+
#endif // TEST_H

0 commit comments

Comments
 (0)