4 ms·
>QML which is a godsend to make modern UIs What advantages does QML provide over using "just the Qt library from C++"? Faster development? I've used an earlier
by vram22 9y ago
>QML which is a godsend to make modern UIs
What advantages does QML provide over using "just the Qt library from C++"? Faster development? I've used an earlier version of Qt (3 or 4) a bit, but never tried QML.
- jcelerier 9y agoIf you are familiar with modern web development, think of Vue.js or React's reactive bindings but as part of the language syntax. See https://qmlbook.github.io/en/ch04/index.html#qml-syntax https://qmlbook.github.io/en/ch04/index.html#qml-syntax e.g. when in "C++ Qt" you'd do : connect(m_button, SIGNAL(clicked()), m_object, SLOT(on_clicked())); or more recently connect(m_button, &QPushButton::clicked, m_object, &MyObj::on_clicked); or even connect(m_button, &QPushButton::clicked, this, [=] { /* do stuff */ }); QML would be : Button { onClicked: /* do stuff * / } Even better is stuff like connect(m_slider, &QSlider::valueChanged, m_object, [=] (int val) { m_item->setWidth(3 * val) }); m_object->setWidth(3 * m_item->value()); which becomes Slider { id: slider } Item { width: 3 * slider.value } It has a slightly stronger type system than JS; not as strong as TypeScript though. The idea is that when you really need strong typing you do it in C++ and expose your objects to QML (which is a one-liner: every object part of the Qt meta-type system can be used from the QML's side and have its signals and slots called there). Of course, the big drawback is the performance loss that you get from going from optimizable C++ to Qt's modified V8 engine. However, if you had a graphics-heavy C++ Qt app that relied on QGraphicsScene / QGraphicsView it could be faster in QML since there it's all OpenGL / D3D12 (and hopefully Vulkan) + a modern scene graph, instead of CPU rendering. So like always, benchmark benchmark benchmark :)
- vram22 9y agoYes, the QML code does seem a lot simpler/shorter. Thanks.