Qt World Summit: Submit your Presentation

Reading and writing files in Symbian^3 with QFile

  • 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
        QDataStream in(&file);
        //read from lista_formulas and writes the formulas in the tablewidget_formulas
        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
    QMessageBox::about(this,"Ok","File saved sucessfully");
    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

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

  • Didn't work :(

  • 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");@

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

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

  • 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
    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()) {
    else {
    qDebug() << "AppData::buildFName() -> return " << fullFileName;
    return fullFileName;


Log in to reply