Converting data
Qt provides a set of classes and functions for easily converting between different types of data. This makes Qt more than just a GUI library; it is a complete platform for software development. The QVariant
class, which we will use in the following example, makes Qt even more flexible and powerful compared to the similar conversion functionalities provided by the C++ standard library.
How to do it…
Let’s learn how to convert various data types in Qt by following these steps:
- Open Qt Creator and create a new Qt Console Application project by going to File | New Project…:
Figure 11.1 – Create a Qt Console Application project
- Open
main.cpp
and add the following headers to it:#include <QCoreApplication> #include <QDebug> #include <QtMath> #include <QDateTime> #include <QTextCodec> #include <iostream>
- In the
main()
function, add the following code to convert...