Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. Qt on BlackBerry and QNX
  4. [Solved] Saving settings to a file
QtWS25 Last Chance

[Solved] Saving settings to a file

Scheduled Pinned Locked Moved Qt on BlackBerry and QNX
8 Posts 6 Posters 4.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    john_god
    wrote on last edited by
    #1

    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 (file.open(QIODevice::ReadOnly)) // if file exists reads from file
    {
    QDataStream in(&file);
    in>>m_CategoriesUnits_List;
    in>>current_category_index;
    file.close();
    //QMessageBox::about(0,"","File does exist.");

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

    @//saving in the destructor
    QFile file("conversions.dat");
    if (file.open(QIODevice::WriteOnly))
    {
    QDataStream out(&file); // we will serialize the data into the file
    out<<m_CategoriesUnits_List;
    out<<current_category_index;
    file.close();
    }
    else
    QMessageBox::about(0,"","Cant save file.");@

    Any ideias for a quick and dirty solution :) ?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goblincoding
      wrote on last edited by
      #2

      Have you looked at what the "error string":http://qt-project.org/doc/qt-4.8/qiodevice.html#errorString returns? Maybe that can give you a starting point as to where things are going wrong.

      http://www.goblincoding.com

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tzander
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          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?

          1 Reply Last reply
          0
          • C Offline
            C Offline
            codenode
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • J Offline
              J Offline
              john_god
              wrote on last edited by
              #6

              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 :)

              1 Reply Last reply
              0
              • J Offline
                J Offline
                john_god
                wrote on last edited by
                #7

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

                This works. Thank you.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  student4life
                  wrote on last edited by
                  #8

                  read this "link":http://developer.blackberry.com/native/documentation/bb10/com.qnx.doc.native_sdk.devguide/com.qnx.doc.native_sdk.devguide/topic/accessible_folders.html for more info regarding filesystem access permissions in BB10

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

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved