CppDepend: A C++ Dependency Analyser

I evaluated the dependency analyser CppDepend on a real-life embedded application. My goal was to find all dependency cycles between classes in the application. I know that the application contains 50+ dependency cycles. CppDepend only found less than 10% of the cycles. Without rewriting the the source code, CppDepend would have found no cycles at...

Comparing Two Floating-Point Numbers

The mathematician Leopold Kronecker is believed to have said: God made the integers, all else is the work of man. And Kronecker didn’t even know the floating-point numbers “made” for computers. Comparing two numbers of type float or double in C++ and related languages is a source for regular errors. When are the if-conditions in...

QCOMPARE with Custom Qt Types

When you write unit tests, you will have to compare the actual value and the expected value. A simplified example with QStrings would look like this. When you run this unit test, the QTest framework will print the actual value "abba" and the expected value "juhu". This is often enough to know what went wrong....

Printing Custom Qt Types with qDebug()

When you define your own C++ types for a Qt application, you want to print their values with qDebug(), qWarning() or qCritical() eventually. The C++ compiler will complain with this error message: The error message tells you to write your own output operator for the QDebug stream and for QCanBusFrame. A custom C++ type that...

QML Engine Deletes C++ Objects Still In Use

Correction: In the original post, I stated that ownership is transferred from C++ to QML by READ functions of Q_PROPERTYs. This is wrong. Ownership is only transferred by Q_INVOKABLE functions and slots, which return a QObject pointer. I corrected my post and my code example. Now, the simple code example crashes as desired. Many thanks...

Best Friends: C++11 Move Semantics and Pimpl

Move semantics is faster than copy semantics, when the compiler can replace expensive copy operations by cheaper move operations, that is, when it can replace a deep copy of a big object by a shallow copy of the pointer to the big object. Hence, classes using the pimpl idiom in combination with move semantics should...

Scroll to top