For a while I thought that I was not able to use Qt c++ classes with qml applications, but I found this: http://doc.qt.io/qt-5/qtqml-cppintegration-definetypes.html.
Now I'm trying to create an instantiable object type. I first ran into "Qwidget: Cannot create a Qwidget without QApplication" reading online it the answer seem to be just to change QGuiApplication to QApplication, but then I get: "ASSERT: " !d->isWidget"
This is the Qt class that I'm trying to use as a qml type: http://doc.qt.io/qt-5/qlcdnumber.html.
Here is my main.cpp:
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QLCDNumber>
#include <QQuickStyle>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QQmlApplicationEngine engine;
qmlRegisterType<QLCDNumber>("LCDNumber",1,0,"LCDNumber");
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
}
Here is what I'm trying to create in main.qml:
...
import LCDNumber 1.0
Window {
...
LCDNumber{
digitCount: 3
intValue: 1
mode: LCDNumber.Dec
segmentStyle: LCDNumber.Flat
smallDecimalPoint: false
value: 0
}
}
Is it really possible to create a qt c++ class in qml? I'm missing something?