Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QML useful if you know C++?



  • Hello everyone,

    a question. If you know C ++, is learning QML useful? I do not understand what real use it has (I do not want to cause discomfort to anyone)

    Thanks in advance


  • Lifetime Qt Champion

    Hi,

    It depends on the type of application you are going to write.



  • There are things QML just won't do, or won't do easily. For our applications we do visual stuff in QML and the working meat of the program in C++.



  • After I started using Qml, I only use c++ if absolutly need. Qml is much fun and faster to write. The Qml declarative language, the bindings and event handlers, after you get the grip of how it works, can make the logic easier and the code cleaner. Of course all depends of the type of app.



  • There is no need for qml - if you like the feel and look of Windows 3.1!



  • @transistor47 QML is not required to develop a Qt application, but I can help you to quickly create a graphic user interface. Much more as doing all in pure C++.

    But there are some dark sides when using QML:

    • QML is a JavaScript based language, and uses a embedded JavaScript engine.
    • QML is slow and requires much more memory as a pure C++ application
    • QML is compiled on the fly, so you can never be sure there is no typo is your QML as long as not all code has been covered!
    • When a QML error occurs, the QML engine just stop execution at the error and all rest of your QML is not executed, this can be very hard to find!

    So my recommendation is to use QML only to create the GUI, do all logical work in C++. This will save you many time and avoids you even more frustration!
    Doing this at the beginning of development is the best you can do.
    Of course you could do many things in QML, don't get caught by the dark side of the force ;-)



  • @transistor47 IMO, QML is much nicer to work with than C++. It is by far the best declarative UI language I've seen. The classic advice you'll hear, as @KroMignon said, is to do the UI in QML and the application logic in C++. But once you've taken the decision to use QML for UI, there's nothing to stop you from using it for application code, other than dogma. I chose a hybrid approach. In addition to UI, I use QML for sqlite database access, because it is so much easier and nicer to do it in QML than C++. Just take a look at some examples and you'll see what I mean. Also, because all my database access is in response to UI events, it's natural to handle it from QML. Furthermore, there's no performance hit because it simply wraps the sqlite C library which does all the real work.

    Don't be afraid of the dark ;-)



  • @KroMignon

    hopefully it's not too long we will see native typed QML and finally never speak of javascript (I think I could be sick) again.



  • @6thC I think you talking about Qt6/QML3, but as far as I know this is a completely new implementation, which kick-out the JavaScript engine to made it compilable and strong typed.
    So nothing comparable with actual Qt5/QML2, and not necessary compatible too!


Log in to reply