Important: Please read the Qt Code of Conduct -

[Solved] Saving settings to a file

  • I'm porting a app, that saves and loads setting to a file using QFile. I'm not using QSettings and a ini file, because I'm using serialization, wich I believe is not supported by QSettings. However the file fails to save. I'm guessing it's because I'm using the app current location, wich probably doesnt allow saving.

    @//loading in the constructor
    QFile file("conversions.dat");
    if ( // if file exists reads from file
    QDataStream in(&file);
    //QMessageBox::about(0,"","File does exist.");

    else //if file does not exists reads from defaul constructor settings
        //QMessageBox::about(0,"","File dont exist.");

    @//saving in the destructor
    QFile file("conversions.dat");
    if (
    QDataStream out(&file); // we will serialize the data into the file
    QMessageBox::about(0,"","Cant save file.");@

    Any ideias for a quick and dirty solution :) ?

  • Have you looked at what the "error string": returns? Maybe that can give you a starting point as to where things are going wrong.

  • Instead of just writing a file, maybe you can puth a real path in the front. Something based on QDir::homePath() would work nicely.

  • Not that there is anything wrong with using a file, but of course you can serialize towards QSettings if you want. Why would you think it is not supported?

  • Change the path. "data/conversations.dat" should work.

  • Thansk for the sugestions guys, I'll tried that and let you know.
    Andre: I read the QSettings docs and got the impression that it would not work, but I'll check again with another eyes :)

  • [quote author="codenode" date="1359624507"]Change the path. "data/conversations.dat" should work.[/quote]

    This works. Thank you.

  • read this "link": for more info regarding filesystem access permissions in BB10

    it is also recommended to use absolute file paths, instead of relative paths

Log in to reply