Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Reading and writing files in Symbian^3 with QFile

Reading and writing files in Symbian^3 with QFile

Scheduled Pinned Locked Moved Mobile and Embedded
7 Posts 4 Posters 4.7k 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

    Hi there. I'm migrating a app from desktop to mobile, and have these questions.
    In MSWindows my app is reading and writing user input information in a file, to store it after the program exit, in the same directory of the exe file. Is this possible in the mobile phone? Whats the exe equivalent for the mobile app, after the sis is installed? The program works ok, but the info is lost after the program exit. Here is some code:

    @QFile file("formulas.dat");

    if (file.open(QIODevice::ReadOnly)) // if file exists reads from file
    {
        lista_formulas.clear();
        QDataStream in(&file);
        in>>lista_formulas;
        file.close();
        //read from lista_formulas and writes the formulas in the tablewidget_formulas
        SetFormulasInTable();
        QMessageBox::about(this,"ok","File exists, read from it");
    }
    else //if file does not exists reads info from constructor default settings
    { ....... }@
    

    more code

    @// writes lista_formulas to the file
    QFile file("formulas.dat");
    if (file.open(QIODevice::WriteOnly))
    {
    QDataStream out(&file); // we will serialize the data into the file
    out<<lista_formulas;
    file.close();
    QMessageBox::about(this,"Ok","File saved sucessfully");
    }
    else
    QMessageBox::about(this,"Error","Couldnt save the file");
    @

    The file is suposed to be created at the first time the app is used. And I get QMessageBox saying that the reading and saving where ok.
    Perhaps this aproach is incorrect for mobile? Should try QSettings ? And I have tried to use explorer to browse the phone directory and I dont have a clue where the installed apps are stored

    1 Reply Last reply
    0
    • ? This user is from outside of this forum
      ? This user is from outside of this forum
      Guest
      wrote on last edited by
      #2

      One way is to bundle the formulas.dat in a qrc file

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

        Didn't work :(

        1 Reply Last reply
        0
        • V Offline
          V Offline
          vishwajeet
          wrote on last edited by
          #4

          In Symbian^3 default file location is c:\private<Process ID>\

          Hence "formulas.dat" will be saved under those directory, its not lost but you are looking in different location.

          If you want to save file in same location as then use

          @QFile file("./formulas.dat");@

          Born To Code !!!

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

            I found the problem, it has not QFile. Reading and writing files was ok, it was a bug, after the file reading, it would still call the default settings.
            Damn bug, it was driving me crazy.

            Thank you all :)

            1 Reply Last reply
            0
            • D Offline
              D Offline
              denis76
              wrote on last edited by
              #6

              QDir::setCurrent ( "c:/" ); before file.open

              1 Reply Last reply
              0
              • AlicemirrorA Offline
                AlicemirrorA Offline
                Alicemirror
                wrote on last edited by
                #7

                Hello, a couple of advices if it can be useful.

                The first is that I tried to embed some system files in an application using qrc files but it was not working. Using the simulator I saw that the reasong that my class accessing the files wasn't working is that the files doesn't exist. I tried to put manually them in the application folder (on Mac it should be in the /Resources/myFolderAppData inside the content of the app created by the simulator) and all run fine.
                Then exploring the forum and reading in-depth the documentation I saw that to have files included in the symbian package needs to add the system files folder in the project. In my case there was only a couple of file, so I used the .pro DEPLOYMENTS adding the file names as described in the documentation. Unfortunately due a but in Qt this option seems not working property. The right solution is to put all the system files in a folder (event if you have only one file) and use DEPLOYMENTFOLDERS:
                @
                folder_01.source = data
                DEPLOYMENTFOLDERS = folder_01
                @
                The other problem idea is to dinamically set / find the folder where you want the appplication will put / save the files. The following code snippet I hope can help you in this (it will work on desktop also I think but only tested and used on Symbian)
                @
                QString AppData::buildFName() {
                QString fullFileName;

                // m_fname, m_folder are the file name and folder where you should put or find the file
                // e.g. m_fname = "test.dat" and m_folder = "/data"
                qDebug() << "AppData::buildFName() m_fname " << m_fname << " m_folder " << m_folder;
                
                // Check if the string is not null
                if (m_fname.isNull() || m_folder.isNull()) {
                    fullFileName.clear();
                }
                else {
                
                    fullFileName.append(QApplication::applicationDirPath());
                    fullFileName.append(m_folder);
                    fullFileName.append(m_fname);
                
                }
                
                qDebug() << "AppData::buildFName() -> return " << fullFileName;
                
                return fullFileName;
                

                }
                @

                Enrico Miglino (aka Alicemirror)
                Balearic Dynamics
                Islas Baleares, Ibiza (Spain)
                www.balearicdynamics.com

                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