Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt vs QML language relevance

Tags:

c++

qt

qml

So, I'm a newbie in Qt and my intent is to familiarize myself with Qt Graphics. However, most of the guides on the internet suggest to use QML instead Qt C++ when it comes to dealing with graphics.

Here is my question: What is the difference between Qt C++ and QML? What does QML give us, that Qt C++ does not?

like image 688
HarvyD Avatar asked May 02 '18 17:05

HarvyD


People also ask

Is QML better than Qt?

If you want to have a Qt app that looks like an native OS app then you must go with QtWidgets. QML allows you to write a much more custom UI. However, in my opinion, QML is simply awesome to write UI's. The way you declare and connect things is blazing fast.

Why should I use QML?

It offers a highly readable, declarative, JSON-like syntax with support for imperative JavaScript expressions, and it allows components to be easily reused and customized within a user interface.

Is Qt good for Android?

Qt is a good choice for businesses that want to build software for several platforms or target both Android and iOS users.

Is Qt worth learning 2022?

If you want a mature and easy framework that is quite well documented and has a great cross platform IDE (QtCreator), go for Qt. If you are a true developer and not just looking for a good paying job, you would learn both.


1 Answers

UI Technology

It's actually not so much a question of QML vs C++, rather it is a question of what UI technology to use with Qt:

  • QtWidgets (code written with C++)
  • QtQuick (code written with QML/JS)
  • HTML5 (via WebEngine, embedded into a widget or QtQuick item)
  • OpenGL (embedded into a widget or QtQuick item)

Leaving aside HTML5 and OpenGL, the question QtWidgets vs QtQuick has been discussed in other placed, for example at Qt Quick vs. Qt Widget and at this Qt DevDays 2014 presentation.

My personal opinion: Use QtWidgets for traditional desktop applications, and QtQuick for mobile and embedded (devices with touchscreen), unless you have good reasons to do otherwise. QtWidgets has better and more mature support for traditional desktop controls, while QtQuick is better for animations and completely custom styling.

One reason to use QtQuick on the desktop is when you want lots of custom animations and styling, at the cost of fighting a bit more with traditional desktop controls such a toolbars, menubars, drag&drop etc.

Language

When choosing QtWidgets, the language is always C++ (well, unless you use the Python bindings). While you can use the Qt Designer tool to visually create UIs, in the end those get compiled to C++.

When choosing QtQuick, the language for the UI parts will be QML and JavaScript. However, in any moderately large QtQuick application, you will at some point also have a C++ part - for example to interface with other C and C++ libraries, for operations that don't have an associated JavaScript API or simply for quicker and more maintainable code than JS. C++ classes and objects can be accessed from QML, check the documentation for more details.

like image 193
Thomas McGuire Avatar answered Oct 24 '22 10:10

Thomas McGuire