Book Image

Qt5 C++ GUI Programming Cookbook

By : Lee Zhi Eng
Book Image

Qt5 C++ GUI Programming Cookbook

By: Lee Zhi Eng

Overview of this book

With the advancement of computer technology, the software market is exploding with tons of software choices for the user, making their expectations higher in terms of functionality and the look and feel of the application. Therefore, improving the visual quality of your application is vital in order to overcome the market competition and stand out from the crowd. This book will teach you how to develop functional and appealing software using Qt5 through multiple projects that are interesting and fun. This book covers a variety of topics such as look-and-feel customization, GUI animation, graphics rendering, implementing Google Maps, and more. You will learn tons of useful information, and enjoy the process of working on the creative projects provided in this book
Table of Contents (16 chapters)
Qt5 C++ GUI Programming Cookbook
About the Author
About the Reviewer

Writing XML data using Stream Writer

Since we have learned how to process data obtained from an XML file in the previous recipe, we will move on to learning how to save data to an XML file. We will continue with the previous example and add to it.

How to do it…

We will learn how to save data into an XML file through the following steps:

  1. First, add another button to mainwindow.ui and set its object name as saveXmlButton and its label as Save XML:

  2. Next, right-click on the button and select Go to slot…. A window will pop up with a list of signals available for selection. Select the clicked() option and click OK. A signal function called on_saveXmlButton_clicked() will now be automatically added to both your mainwindow.h and mainwindow.cpp file by Qt:

  3. After that, add the following code to the on_saveXmlButton_clicked() function:

    QXmlStreamWriter xml;
    QString filename = QFileDialog::getSaveFileName(this, "Save Xml", ".", "Xml files (*.xml)");
    QFile file(filename);
    if (! ...