Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Qt vs QML language relevance
Forum Updated to NodeBB v4.3 + New Features

Qt vs QML language relevance

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Caitlyn81
    wrote on 30 May 2019, 04:34 last edited by Caitlyn81
    #1

    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?

    mcdvoice

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 30 May 2019, 05:24 last edited by
      #2

      First, I'll list more graphic-related stuff in Qt, to give you a broader picture:

      • QtWidgets - standard components for creating windows, dialogs etc. Useful mostly on desktops, but work on mobile platforms, too
      • QtQuick (QML) - declarative components, using a new language (QML and JavaScript). Great on mobile platforms, embedded devices etc. but work on desktops, too
      • Qt3D - well, as the name implies, a 3D toolkit within Qt
      • QGraphicsView - part of Qt widgets, allows building 2D scenes, painting shapes etc.
      • QPainter - the base painting mechanism of QtWidgets
      • QtSceneGraph - base painting mechanism of QtQuick
      • QtCharts - a module useful for creating charts

      Now, with that information out, let's focus on your questions:

      What is the difference between Qt C++ and QML?

      There are so many differences it's hard to start somewhere. C++ is an imperative language (you state, line by line, what the CPU has to do) while QML is declarative (you declare how app should behave, and QML engine figures out the rest). This is an important difference, takes some time to get used to.

      To explain it in short: imagine you have a variable temperature and you have a thermometer which updates the reading every second. In C++, you would do something like this:

      connect(thermometer, &Thermal::reading, this, &App::updateValue);
      /// [...]
      void updateValue(int temp)
      {
        value = temp;
        // Then you probably also want to update your GUI view
      }
      

      In QML, the same is achieved with:

      value: thermometer.temp
      

      QML engine knows that value needs to change each time temp changes.

      Further differences:

      • QML is an interpreted language and uses JavaScript to evaluate expressions. C++ is compiled
      • QML allows one to easily and quickly design new interfaces, especially when they involve a lot of animations, timers etc. (that's why they are recommended on mobile platforms)
      • however, with QML it's a bit harder to create large architectures, it gets rather complex in the process
      • with C++ you get access to a lot of additional technologies aimed at optimizing applications (valgrind, asan, perf, compiler optimizations etc.), in QML there aren't so many tools
      • with QtWidgets, architectures are usually clearer and IDEs have no problem to follow symbols, find their uses etc.

      Now, to make matters even more complicated: you can use C++ with QML. You can also (via external module - DeclarativeWidgets) use widgets in QML. Under the hood it's all C++ anyway ;-)

      I probably confused you even more. I'd recommend trying to create some simple app in both technologies and you'll have a much clearer view of the matter.

      From experience - both QML and QtWidgets are in active use, it's not like one technology is winning over the other. They are both good and useful, for slightly different use cases.

      (Z(:^

      1 Reply Last reply
      2

      1/2

      30 May 2019, 04:34

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved