O'Reilly logo

Qt 5 Projects by Marco Piccolino

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Introducing the almighty QVariant

Besides QObject, another type which makes Qt code so powerful is QVariant, a type which acts like a union for the most common Qt data types (http://doc.qt.io/qt-5.9/qvariant.html).

QVariant's usefulness derives from the fact that it represents an abstraction over several Qt and C++ built-in data types, and allows conversion between them. Thanks to its various constructors, QVariant stores both a value and a specific type (QString, int, and so on). The value can be retrieved (by copy) by invoking one of the built-in methods ( toString, toInt), and the stored type via the typeName method. Conversion between types happens via the convert and canConvert methods.

QVariant plays a crucial role in supporting Qt's ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required