Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Qt5 C++ GUI Programming Cookbook

You're reading from   Qt5 C++ GUI Programming Cookbook Design and build a functional, appealing, and user-friendly graphical user interface

Arrow left icon
Product type Paperback
Published in Jul 2016
Publisher Packt
ISBN-13 9781783280278
Length 300 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Lee Zhi Eng Lee Zhi Eng
Author Profile Icon Lee Zhi Eng
Lee Zhi Eng
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Look and Feel Customization FREE CHAPTER 2. States and Animations 3. QPainter and 2D Graphics 4. OpenGL Implementation 5. Building a Touch Screen Application with Qt5 6. XML Parsing Made Easy 7. Conversion Library 8. Accessing Databases 9. Developing a Web Application Using Qt Web Engine Index

Data conversion


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 be using in the following example, makes Qt even more flexible and powerful compared to 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:

  1. Open up Qt Creator and create a new Qt Console Application project by going to File | New File or Project:

  2. Next, open up main.cpp and add the following headers to it:

    #include <QCoreApplication>
    #include <QDebug>
    #include <QtMath>
    #include <QDateTime>
    #include <QTextCodec>
    #include <iostream>
  3. Then, in the main() function, add the following code to convert a string to a number:

    int numberA = 2;
    QString numberB = "5";
    qDebug() << "1) " << "2 + 5 =" << numberA...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £16.99/month. Cancel anytime