Writing JSON data to a text file
Since we have learned how to process data obtained from a JSON file in the previous recipe, we will move on to learning how to save data to a JSON file. We will continue with the previous example and add to it.
How to do it…
We will learn how to save data in a JSON file through the following steps:
- Add another button to
mainwindow.ui
, then set its object name assaveJsonButton
and its label asSave JSON
:
Figure 10.4 – Adding the Save JSON button
- 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 calledon_saveJsonButton_clicked()
will now be automatically added to both yourmainwindow.h
andmainwindow.cpp
files by Qt:
Figure 10.5 – Selecting the clicked() signal and pressing OK
- Add the following code to the...