Skip to content

KDAB contributions to Qt 5.7

Hello, and welcome to the usual appointment with a new release of Qt!

Qt 5.7 has just been released, and once more, KDAB has been a huge part of it (we are shown in red on the graph):

Qt Project commit stats, up to June 2016. From http://www.macieira.org/blog/qt-stats/

Qt Project commit stats, up to June 2016. From http://www.macieira.org/blog/qt-stats/

In this blog post I will show some of the outstanding contributions by KDAB engineers to the 5.7 release.

Qt 3D

The star of Qt 5.7 is the first stable release of Qt 3D 2.0. The new version of Qt 3D is a total redesign of its architecture into a modern and streamlined 3D engine, exploiting modern design patterns such as entity-component systems, and capable to scale due to the heavily threaded design. This important milestone was the result of a massive effort done by KDAB in coordination with The Qt Company.

neptune-pbr1

If you want to know more about what Qt 3D can do for your application, you can watch this introductive webinar recorded by KDAB’s Dr. Sean Harmer and Paul Lemire for the 5.7 release.

Qt on Android

Thanks to KDAB’s BogDan Vatra, this release of Qt saw many improvements to its Android support. In no particular order:

  • Qt can now be used to easily create Android Services, that is, software components performing background tasks and that are kept alive even when the application that started them exits. See here for more information.
  • The QtAndroidExtras module gained helper functions to run Runnables on the Android UI thread. They are extremely useful for accessing Android APIs from C++ code that must be done on Android UI thread. More info about this is available in this blog post by BogDan.
  • Another addition to the QtAndroidExtras module is the QtAndroid::hideSplashScreen function, which allows a developer to programmatically hide the splash screen of their applications.
  • The QtGamepad module gained Android support.

Performance and correctness improvements

A codebase as big as Qt needs constant fixes, improvements and bugfixes. Sometimes these come from bug reports, sometimes by reading code in order to understand it better, and in some other cases by analyzing the codebase using the latest tools available. KDAB is committed to keeping Qt in a great shape, and that is why KDAB engineers spend a lot of time polishing the Qt codebase.

Some of the results of these efforts are:

  • QHash gained equal_range, just like QMap and the other STL associative container. This function can be used to iterate on all the values of a (multi)hash that have the same key without performing any extra memory allocation. In other words, this code:
    // BAD!!! allocates a temporary QList 
    // for holding the values corresponding to "key"
    foreach (const auto &value, hash.values(key)) {
    }
    

    can be changed to

    const auto range = hash.equal_range(key);
    for (auto i = range.first; i != range.second; ++i) {
    }
    

    which never throws (if hash is const), expands to less code and does not allocate memory.

  • Running Qt under the Undefined Behavior Sanitizer revealed dozens of codepaths where undefined behaviour was accidentally triggered. The problems ranged from potential signed integer overflows and shift of negative numbers to misaligned loads, invalid casts and invalid calls to library functions such as memset or memcpy. KDAB’s Senior Engineer Marc Mutz contributed many fixes to these undefined behaviours, fixes that made their way into Qt 5.6.1 and Qt 5.7.
  • Some quadratic loops were removed from Qt and replaced with linear or linearithmic ones. Notably, an occurrence of such loops in the Qt Quick item views caused massive performance degradations when sorting big models, which was fixed in this commit by KDAB’s engineer Milian Wolff.
  • Since Qt 5.7 requires the usage of a C++11 compiler, we have starting porting foreach loops to ranged for loops. Ranged for loops expand to less code (because there is no implicit copy taking place), and since compilers recognize them as a syntactic structure, they can optimize them better. Over a thousand occurrences were changed, leading to savings in Qt both in terms of library size and runtime speed.
  • We have also started using C++ Standard Library features in Qt. While Qt cannot expose STL types because of its binary compatibility promise, it can use them in its own implementation. A big advantage of using STL datatypes is that they’re generally much more efficient, have more features and expand to a lot less code than Qt counterpart. For instance, replacing some QStack usages with std::stack led to 1KB of code saved per instance replaced; and introducing std::vector in central codepaths (such as the ones in QMetaObjectBuilder) saved 4.5KB.
  • While profiling Qt3D code, we found that the mere act of iterating over resources embedded in an application (by means of QDirIterator) uncompressed them. Then, reading a given resource via QFile uncompressed it again. This was immediately fixed in this commit by KDAB’s Director of Automotive, Volker Krause.

Other contributions

Last but not least:

  • It is now possible to use the Qt Virtual Keyboard under QtWayland compositors.
  • The clang-cl mkspec was added. This mkspec makes it possible to build Qt using the Clang frontend for MSVC. Stay tuned for more blog posts on this matter. 🙂
  • A small convenience QFlag::setFlag method was added, to set or unset a flag in a bitmask without using bitwise operations.

About KDAB

KDAB is a consulting company offering a wide variety of expert services in Qt, C++ and 3D/OpenGL and providing training courses in:

KDAB believes that it is critical for our business to contribute to the Qt framework and C++ thinking, to keep pushing these technologies forward to ensure they remain competitive.

Categories: KDAB Blogs / KDAB on Qt / OpenGL / Qt3D

2 thoughts on “KDAB contributions to Qt 5.7”

  1. A bit puzzled about the graph. You seem to have been there at initial feature input, missing out at the stabilization… which seems strange.

    And I didn’t know intel is contributing there… don’t know even just one project of them making use of Qt. Which makes it quite strange they contribute … not a huge amount, but quite a bit.

Leave a Reply

Your email address will not be published. Required fields are marked *