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

[SOLVED] best method to save data on users computer



  • Hi, i need to save a few different lists to a users computer which has not got admin privileges.

    (the lists are of a custom data type called media and contains fields such as the name, path, size, duration ect.)

    im wondering what the fastest and most robust way to save data on the users computer would be without any administrator rights.
    at the moment im thinking the solutions are XML or SQL, however i have no idea which is more suited to my purpose.

    thanks for any suggestions.


  • Lifetime Qt Champion

    Hi,

    Is only your application using these data ?

    If so you have "QDesktopServices::storageLocation":http://qt-project.org/doc/qt-4.8/qdesktopservices.html#storageLocation for Qt 4 and "QStandardPaths::writableLocation":http://qt-project.org/doc/qt-5.0/qtcore/qstandardpaths.html#writableLocation for Qt 5

    Database or XML depends essentially on the structure of the data. You can also use SQLite to avoid installing a database server

    Hope it helps



  • Hello,

    In my opinion the fastest way for sure would be to use XML.
    I personally tend to use XML if data needs to be stored locally for a user.
    But SQL when the data needs to be shared between multiple users over network, but I have to yet use SQL with Qt. Anyway, I would go for XML, more or less easy to use and good for storing multiple lists.



  • thanks for the reply - SQLite sounds like a viable solution.

    yes its only my application.

    my data structure is of this format:
    @
    struct Point
    {
    QString name;
    QString path;
    QString notes
    };
    @



  • just a quick question - if i do use XML xcoder. in Windows where should i store the XML file?


  • Lifetime Qt Champion

    The same place you would save the database, in the folder returned for DataLocation since it's specific for your software



  • ok cheers SGalst - im going to use XML and save to
    @
    QString dataDirectory = QStandardPaths::writableLocation(QStandardPaths::DataLocation);--@

    one more thing, once i have read the contents of the XML file into memory where can i store the data so that it can be accessed through out my program (like from within my custom widgets and also from my mainwindow)

    should i make a static 'data' class?


  • Lifetime Qt Champion

    Then I would go for the Model/View paradigm, create one model with your data and make your widget act like "views" on that model


Log in to reply