Today’s blog post is about something that should be simple and apparently it causes trouble: how to declare a qHash overload for a custom datatype. This is necessary when we want to use custom datatypes as keys in a QHash. From the documentation: A QHash’s key type has additional requirements other than being an assignable […]
Blog Archives
QStringView Diaries: Zero-Allocation String Splitting QStringTokenizer merged for 6.0
After four months of intensive development work, I am happy to announce that the first QStringTokenizer commits have landed in what will eventually become Qt 6.0. The docs should show up, soon. While the version in Qt will be Qt 6-only, KDAB will release this tool for Qt 5 as part of its KDToolBox productivity […]
C++ Modernization Brochure
New releases of the C++ language maintain incredibly strong backwards compatibility, making it easy to keep older C++ code working properly as standards march forward. C++11, C++14, and C++17 have transformed the C++ language in ways that make it as programmer-friendly as more recent languages but with many essential benefits that continue to make it […]
Tuple And Pair in C++ APIs? A Simple Design Goal to Improve Your C++ APIs
Quick: When you design C++ APIs, when and how should you use pair and tuple? The answer is as simple as it is surprising: Never. Ever. When we design APIs, we naturally strive for qualities such as readability, ease-of-use, and discoverability. Some C++ types are enablers in this regard: std::optional, std::variant, std::string_view/gsl::string_span, and, of course, […]
Goodbye, Q_FOREACH A porting guide to C++11 ranged for-loops
Q_FOREACH (or the alternative form, foreach) will be deprecated soon, probably in Qt 5.9. Starting with Qt 5.7, you can use the QT_NO_FOREACH define to make sure that your code does not depend on Q_FOREACH. You may have wondered what all the fuss is about. Why is there a continuous stream of commits going to into Qt […]
Very explicit operator bool Is the Safe Bool Idiom still useful in C++11 / C++14?
From time to time I scroll through Qt-related forums and mailing lists, and whenever possible I try to help fellow developers out. The other day a StackOverflow thread caught my attention: a developer was asking “What is the purpose of operator RestrictedBool in QScopedPointer?” Indeed, looking at QScopedPointer‘s implementation, one notices the strange RestrictedBool usage. […]
QRegion will be iterable in Qt 5.8 - seamless integration with C++11 range-for
A novel solution to an old problem The QRegion class specifies a clip region for a painter. You can also query a QPaintEvent for the region() to limit the paint operations necessary in partial repaints. A region can be anything from a simple rectangle to a bitmap mask, but virtually all code that inspects a […]
How to use static analysis to improve performance
It’s usually said “only improve performance where a profiler tells you to“. I don’t completely agree. Take a big C++ library like Qt: can you profile all classes and all code paths ? It would take a couple of years to accomplish and analyse the results. It’s expensive: It usually only happens if the speed-up […]
Reducing relocations with Q_STRINGTABLE
Qt is a native library at the heart. As a native (C++) library, it already outperforms most higher-level language libraries when it comes to startup performance. But if you’re using native languages, you usually do so because you need to get the most out of the available hardware and being just fast may not be […]
Improving the speed of C++ applications Fast code matters - Milian Wolff
…just think of performance constrained embedded platforms. But how do you make your C++ application faster? This talk will show you how to find bottlenecks in a C++ program using various tools.