Lets try with a very simple example
main.cpp
#include <QtQml>
int main(int argc, char **argv)
{
qmlRegisterType<QTimer>("APP_CHILD", 1, 0, "AppChild");
QQmlEngine engine;
QQmlComponent component(&engine);
component.
setData("import APP_CHILD 1.0\n\nAppChild { }",
QUrl());
qDebug() << "created object=" << component.create();
return 0;
}
#include <QtQml>
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
qmlRegisterType<QTimer>("APP_CHILD", 1, 0, "AppChild");
QQmlEngine engine;
QQmlComponent component(&engine);
component.setData("import APP_CHILD 1.0\n\nAppChild { }", QUrl());
qDebug() << "created object=" << component.create();
return 0;
}
To copy to clipboard, switch view to plain text mode
appchildtest.pro
TEMPLATE = app
TARGET = appchildtest
INCLUDEPATH += .
# Input
SOURCES += main.cpp
QT += qml
TEMPLATE = app
TARGET = appchildtest
INCLUDEPATH += .
# Input
SOURCES += main.cpp
QT += qml
To copy to clipboard, switch view to plain text mode
Executing that should give you an output like this:
created object= QTimer(0xc2b250)
Once you've veryfied that, add you class and register it instead of QTimer.
Cheers,
_
Bookmarks