×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Regular Contributor
    Join Date
    Jan 2011
    Posts
    122

    Resource file- working when retrieving data from .txt, NOT working when saving to it

    Hello,

    I've added a resource file(.txt) on my project and accessing it to retrieve the contents works fine. However, if I try to delete contents or add another line, it doesn't take effect. Is the path different when reading compare to writing to the same file?

    If I test it on the simulator, neither works, so I explicitly set the complete filepath for both functions, then reading and writing from and to the file works. But when it comes to testing it with the device(Nokia N8), retrieveAchievementsFromFile() works, and the other doesn't. Below is my exact code. Can anyone check what am I doing wrong here?

    QStringList FileManager::retrieveAchievementsFromFile()
    {
    QStringList ListLines;

    //Open file
    QFile file(":/files/achievements.txt");
    if( file.open(QIODevice::ReadOnly | QIODevice::Text) )
    {
    QTextStream in(&file);
    QString line;
    while(!in.atEnd())
    {
    line = in.readLine();
    ListLines.append(line);
    }

    //Close file
    file.close();
    }
    return ListLines;
    }

    void FileManager::saveAchievementToFile(QString achievementRecord)
    {
    QFile file(":/files/achievements.txt");
    if( file.open( QIODevice::ReadWrite | QIODevice::Text) )
    {
    QTextStream writeData(&file);
    writeData << achievementRecord << endl;
    file.close();
    }

    }

    Thanks!

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: Resource file- working when retrieving data from .txt, NOT working when saving to

    first thing afaik editing of the file will not work with qrc resource files, second giving a complete path in desktop is is a wrong approach the reason its nor working is the file might not be at that path from where you are opening that.

    The best thing should first transfer the file inside the phone to some directory and then do the required things there.

  3. #3
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Resource file- working when retrieving data from .txt, NOT working when saving to

    Resource files are read-only.

  4. #4
    Regular Contributor
    Join Date
    Jan 2011
    Posts
    122

    Re: Resource file- working when retrieving data from .txt, NOT working when saving to

    I only set it to a complete path when i was testing it on the simulator. Of course, I wouldn't include it on the final program. I just want to test if my process of writing to and from a txt file works. But it seems it doesn't with a qrc file.

    So, I should NOT use a qrc file if I were to edit it? I didn't expect qrc files are uneditable. Oh well, if that's the case, where do you think I should point the files when deployed to the device(i mean safest path)?
    Last edited by vilmavaliente; 2011-02-19 at 16:44.

  5. #5
    Nokia Developer Moderator
    Join Date
    Sep 2004
    Location
    Tampere, Finland
    Posts
    11,359

    Re: Resource file- working when retrieving data from .txt, NOT working when saving to

    Use QCoreApplication::applicationDirPath ()
    -- Lucian

    If you are not yet a DVLUP member it is time to correct that mistake :) Click here to join: http://www.dvlup.com/lucian/Invite

  6. #6
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Resource file- working when retrieving data from .txt, NOT working when saving to

    If you considered at all how it worked, you'd realize that a qrc file is compiled into a qrc_xxx.cpp file which is just a bunch of C++ static declarations that get compiled into your object module.

  7. #7
    Regular Contributor
    Join Date
    Jan 2011
    Posts
    122

    Re: Resource file- working when retrieving data from .txt, NOT working when saving to

    @Itomuta, thanks, I will use that.

    @danhicksbyron, thanks for elaborating.

    This is out of this thread, you may or may not answer this - since Nokia is shifting to Windows Phone OS, what will happen to Qt? Will Nokia totally ditch all their Symbian phones or still maintain(development will still exist, bugs will be fix etc) existing models?

  8. #8
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Resource file- working when retrieving data from .txt, NOT working when saving to

    You want the official line, or what everyone believes is actually going to happen? There are threads on both topics in Developer Discussions/Open Discussions.
    Last edited by danhicksbyron; 2011-02-20 at 13:25.

Similar Threads

  1. how to create a txt file in current working directroy?
    By fengwujiutian in forum Mobile Java General
    Replies: 1
    Last Post: 2010-03-04, 11:59
  2. Replies: 3
    Last Post: 2009-03-12, 19:04
  3. File Run Not working when self signed
    By kdurga in forum Symbian
    Replies: 3
    Last Post: 2008-07-16, 08:20
  4. Socket Connection not working when application signed
    By deanandreakis in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2005-12-03, 15:32
  5. HTTPConnection not working when deployed on 6310i.
    By JStar in forum Mobile Java General
    Replies: 1
    Last Post: 2002-06-04, 09:53

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×