Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to deal with Data from files and widgets



  • Hello,

    I am pretty new to qt programming and I would like to know what is the good way to do the following :

    In my application, I decided to let the user create widgets dynamically when he presses on a "Add new Widget X" button and once the widget is created, I store the data of the widget in a json file in order to be recreate the widget the next time he closes the close, then open the application.

    So far, don't have a "model" to retrieve the data. What I do is : I have a directory in which i put all of my json files for that kind of widet. I name those files like this "widgetX_1.json", "widgetX_2.json" and so on. However, this does not seem to be the propper way,

    I need some guidance please


  • Lifetime Qt Champion

    Hi,

    Is the saving automated ?
    Does the file name mean anything ?



  • Hi,

    The name of the directories/files per se does not mean anything. It just needs to be consistent.

    A part of my application consists of creating Flashcard sets so I have a folder in which I regroup each flashcard set in its own directory. Inside them there is two things : a json file (always named set.json) that contains the informations about the set such as the name of the set given by the user, the text the flashcards contains and path to an image for that flashcard. The second thing is a directory that contains the images. Their name is somewhat meaningful because in the json flashcard1 is associated with flashcard1.png and so on.

    flashcardSet.png
    flashcardSet2.png


  • Lifetime Qt Champion

    Looks like something a small SQLite database could handle rather than filling your hard drive with files.



  • Hi,

    Just to make sure I understand well, you suggest that when the user creates the widget I would store its relevent attributes (name, description, image, etc) in a SQLite database and when the user restarts the application, I would read from the SQLite database to create the widgets, is that correct ?


  • Lifetime Qt Champion

    That's the idea yes.


Log in to reply