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 the QDomDocument class

In this example, we will learn how to write data to an XML file using the QDomDocument class. We will continue from the previous example and just add stuff to it.

How to do it…

To learn how to save data into an XML file using the QDomDocument class, let's do the following:

  1. First of all, add the second button to the UI, called Save XML:

  2. Right-click on the Save XML button and select Go to slot…. Then, pick the clicked() option and click OK. A new clicked() slot function will now be added to your source files.

  3. After that, write the following code within the button's clicked() slot function:

  4. Compile and run the program now and click on the Save XML button. Enter your desired filename in the save file dialog and click Save.

  5. Open up the XML file you just saved in Step 4 with any text editor and you should see something like this:

    <!DOCTYPE contact>
    <contact category="Family">
      <name>John Doe</name>