Skip to content

Commit

Permalink
QClassInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
cppcloud committed Jun 30, 2024
1 parent edbaa8f commit de935e4
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
27 changes: 27 additions & 0 deletions 6-6-QClassINFO/6-6-QClassINFO.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
QT -= gui

CONFIG += c++11 console
CONFIG -= app_bundle

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
main.cpp \
test.cpp

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

HEADERS += \
test.h
27 changes: 27 additions & 0 deletions 6-6-QClassINFO/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <QCoreApplication>
#include <QDebug>
#include <QMetaObject>
#include <QMetaProperty>
#include <QMetaClassInfo>
#include <QMetaMethod>
#include <QVariant>
#include "test.h"


void listClassInfo(QObject *obj) {
qInfo() << obj->metaObject()->className();
for(int i = 0; i < obj->metaObject()->classInfoCount(); i++) {
QMetaClassInfo c = obj->metaObject()->classInfo(i);
qInfo() << "Property: " << c.name() << " = " << c.value();
}
}

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);

test t;
listClassInfo(&t);

return a.exec();
}
6 changes: 6 additions & 0 deletions 6-6-QClassINFO/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "test.h"

test::test(QObject *parent) : QObject(parent)
{

}
20 changes: 20 additions & 0 deletions 6-6-QClassINFO/test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef TEST_H
#define TEST_H

#include <QObject>

class test : public QObject
{
Q_OBJECT
Q_CLASSINFO("Author", "Bryan Cairns")
Q_CLASSINFO("Url", "http://www.voidrealms.com")

public:
explicit test(QObject *parent = nullptr);

signals:

public slots:
};

#endif // TEST_H

0 comments on commit de935e4

Please sign in to comment.