2014-07-19 16:26:08 +00:00
|
|
|
#include <QGuiApplication>
|
|
|
|
#include <QQmlApplicationEngine>
|
|
|
|
#include <QQmlContext>
|
|
|
|
#include <QMetaMethod>
|
|
|
|
#include <DynamicQObject.h>
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
QGuiApplication app(argc, argv);
|
|
|
|
|
|
|
|
DynamicQObject dynamicQObject;
|
2014-08-30 16:46:34 +00:00
|
|
|
|
|
|
|
int signalIndex;
|
|
|
|
dynamicQObject.registerSignal("nameChanged", {QMetaType::QString}, signalIndex);
|
|
|
|
|
2014-07-19 16:26:08 +00:00
|
|
|
int slotIndex;
|
2014-08-30 16:46:34 +00:00
|
|
|
dynamicQObject.registerSlot("foo", QMetaType::Void, {}, slotIndex);
|
2014-12-24 13:30:41 +00:00
|
|
|
dynamicQObject.registerSlot("bar", QMetaType::Int, {QMetaType::Int}, slotIndex);
|
|
|
|
dynamicQObject.registerSlot("getName", QMetaType::QString, {}, slotIndex);
|
|
|
|
dynamicQObject.registerSlot("setName", QMetaType::Void, {QMetaType::QString}, slotIndex);
|
|
|
|
|
|
|
|
dynamicQObject.registerProperty("name", QMetaType::QString, "getName", "setName", "nameChanged");
|
2014-07-19 16:26:08 +00:00
|
|
|
|
|
|
|
QQmlApplicationEngine engine;
|
|
|
|
engine.rootContext()->setContextProperty("dynamicQObject", QVariant::fromValue<QObject*>(&dynamicQObject));
|
|
|
|
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
|
|
|
|
|
2014-08-30 16:46:34 +00:00
|
|
|
QVariantList list;
|
2014-12-28 13:56:10 +00:00
|
|
|
list << "NewName";
|
2014-08-30 16:46:34 +00:00
|
|
|
dynamicQObject.emitSignal("nameChanged", list);
|
|
|
|
|
2014-07-19 16:26:08 +00:00
|
|
|
return app.exec();
|
|
|
|
}
|