×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    27

    Question How to save data in Symbian phones

    Hi,

    What is the best way to save data. I just need to save some data when closing the app and reading it back when reopening the application.

    Is saving an xml document to a file a good option? Where does the file end up in a real device?

    Thanks

  2. #2
    Registered User
    Join Date
    Nov 2010
    Posts
    9

    Re: How to save data in Symbian phones

    hello there,

    im new for qt too.. it's really hard to find the answer. so, i think i would tell you from my experience.
    you can use QSettings to save and restore the data but it's not that flexible.

    i use xml instead and it seems to work ok for me.

    you can specify where you want to save the file.
    first, use QDir to get currentPath

    or read this tutorial. it will tell you how to get application path
    http://wiki.forum.nokia.com/index.ph...ate_path_in_Qt

    then you can just save it under that path.

    the file will end up somewhere like c:/private/xxxxxxxx (xxxxxxx is UID)

    hope it help
    TJ

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

    Re: How to save data in Symbian phones

    Open a file with the QFile class. Use a name with no directory. The file will be written into the application's private home directory.

    You can use XML if you're a glutton for punishment, I suppose.

  4. #4
    Registered User
    Join Date
    Feb 2010
    Posts
    210

    Re: How to save data in Symbian phones

    I use this:
    Main.cpp;
    Code:
       
        a.setOrganizationName("AppName");
        a.setOrganizationDomain("website.com");
        a.setApplicationName("AppName");
    app.cpp
    Code:
        
        QString str;
        //set up settings file in corect path on the particular device
        str = QCoreApplication::applicationDirPath(); //returns path of app exe
        settings.setPath(QSettings::NativeFormat, QSettings::UserScope, str);
    In Symbian this puts the save file (AppName.conf) in the application private dir instead of the /sys/bin where the application exe resides. In Windows it sets up a folder "AppName" in the registry where it stores the save.conf file.
    I find this works well in all the Qt supported OS's . By setting the appName in main, all of your apps will use the same folder for their respective save files which is nice too.
    Cheers,
    Jon

  5. #5
    Super Contributor
    Join Date
    Jul 2008
    Posts
    2,020

    Re: How to save data in Symbian phones

    Here is the class I use. Works decently well on Symbian for me.

    Source:
    Code:
    /*
     * ApplicationPrefs.cpp
     *
     *  Created on: Dec 31, 2009
     *      Author: TAMHAN
     */
    #include <QDir>
    #include <QFile>
    
    #include "ApplicationPrefs.h"
    
    bool ApplicationPrefs::playMusic;
    hintparamt ApplicationPrefs::hintsettings;
    highscoretype ApplicationPrefs::highscores[6];
    int ApplicationPrefs::volume;
    
    
    
    ApplicationPrefs::ApplicationPrefs()
    	{
    	// TODO Auto-generated constructor stub
    
    	}
    
    ApplicationPrefs::~ApplicationPrefs()
    	{
    	// TODO Auto-generated destructor stub
    	}
    
    void ApplicationPrefs::initPrefs()
    {
    	QFile prefFile(QDir::currentPath() + "/prefs.tmgn");
    	if(!prefFile.open(QIODevice::ReadOnly))
    	{
    		defaultPrefs();
    		return;
    	}
    	QDataStream in(&prefFile);
    	quint32 version;
    	in >> version; // not needed for this v
    	in.readRawData((char*) ApplicationPrefs::highscores, sizeof(ApplicationPrefs::highscores[0])*6);
    	
    	in.readRawData((char*) &ApplicationPrefs::hintsettings, sizeof(ApplicationPrefs::hintsettings));
    	in >> ApplicationPrefs::playMusic;
    	in >> ApplicationPrefs::volume;
    	prefFile.close();
    }
    
    void ApplicationPrefs::savePrefs()
    {
    	QFile prefFile(QDir::currentPath() +"/prefs.tmgn");
    		if(!prefFile.open(QIODevice::WriteOnly))
    		{
    			defaultPrefs();
    			return;
    		}
    		QDataStream out(&prefFile);
    		quint32 version=1;
    		out << version; // not needed for this v
    		out.writeRawData((char*) ApplicationPrefs::highscores, sizeof(ApplicationPrefs::highscores[0])*6);
    		out.writeRawData((char*) &ApplicationPrefs::hintsettings, sizeof(ApplicationPrefs::hintsettings));
    		out << ApplicationPrefs::playMusic;
    		out << ApplicationPrefs::volume;
    		prefFile.close();
    }
    
    void ApplicationPrefs::defaultPrefs()
    {//Complex structure needed for TR while keeping old char prefs intact
    	QByteArray esyArray=tr("ESY").toLatin1();
    	QByteArray vsyArray=tr("VSY").toLatin1();
    	QByteArray emperorArray=tr("The emperor").toLatin1();
    	QByteArray kingArray=tr("The king").toLatin1();
    	QByteArray lordArray=tr("The lord").toLatin1();
    	QByteArray commanderArray=tr("The commander").toLatin1();
    	QByteArray controllerArray=tr("The controller").toLatin1();
    	QByteArray stArray=tr("The subject teacher").toLatin1();
    	strcpy(ApplicationPrefs::highscores[0].difficulty,esyArray.data());
    	strcpy(ApplicationPrefs::highscores[0].name,emperorArray.data());
    	ApplicationPrefs::highscores[0].secs=30*15;
    	strcpy(ApplicationPrefs::highscores[1].difficulty,esyArray.data());
    	strcpy(ApplicationPrefs::highscores[1].name,kingArray.data());
    	ApplicationPrefs::highscores[1].secs=30*20;
    	strcpy(ApplicationPrefs::highscores[2].difficulty,esyArray.data());
    	strcpy(ApplicationPrefs::highscores[2].name,lordArray.data());
    	ApplicationPrefs::highscores[2].secs=30*25;
    	strcpy(ApplicationPrefs::highscores[3].difficulty,esyArray.data());
    	strcpy(ApplicationPrefs::highscores[3].name,commanderArray.data());
    	ApplicationPrefs::highscores[3].secs=30*30;
    	strcpy(ApplicationPrefs::highscores[4].difficulty,esyArray.data());
    	strcpy(ApplicationPrefs::highscores[4].name,controllerArray.data());
    	ApplicationPrefs::highscores[4].secs=30*35;
    	strcpy(ApplicationPrefs::highscores[5].difficulty,vsyArray.data());
    	strcpy(ApplicationPrefs::highscores[5].name,stArray.data());
    	ApplicationPrefs::highscores[5].secs=30*50;
    	ApplicationPrefs::playMusic=true;
    	ApplicationPrefs::volume=70;
    }
    The lines above are the best I have to offer.If anyone of you is of more advanced knowledge, I ask for your patience and understanding! - unknown arab poet
    http://www.tamoggemon.com - Symbian blog - Windows Phone blog
    My other blogs:
    webOS blog iPhone blog BlackBerry blog Samsung bada blog Android blog

  6. #6
    Super Contributor
    Join Date
    Jul 2008
    Posts
    2,020

    Re: How to save data in Symbian phones

    And here is the header:
    Code:
    /*
     * ApplicationPrefs.h
     *
     *  Created on: Dec 31, 2009
     *      Author: TAMHAN
     */
    
    #ifndef APPLICATIONPREFS_H_
    #define APPLICATIONPREFS_H_
    
    #include "BallZEngine.h"
    #include "../hal/HalConstants.h"
    
    class ApplicationPrefs : public QObject
    	{
    	Q_OBJECT
    public:
    	ApplicationPrefs();
    	~ApplicationPrefs();
    
    public:	
    	static hintparamt hintsettings;
    	static highscoretype highscores[6];
        static void initPrefs();
        static void savePrefs();
    	static bool playMusic;
        static int volume;
    	
    private:
            static void defaultPrefs();
    	};
    
    #endif /* APPLICATIONPREFS_H_ */
    The lines above are the best I have to offer.If anyone of you is of more advanced knowledge, I ask for your patience and understanding! - unknown arab poet
    http://www.tamoggemon.com - Symbian blog - Windows Phone blog
    My other blogs:
    webOS blog iPhone blog BlackBerry blog Samsung bada blog Android blog

Similar Threads

  1. how to save data in data query dialog
    By karan kumar in forum Symbian
    Replies: 4
    Last Post: 2010-06-08, 12:07
  2. how to save data in data query dialog
    By manishpinjani in forum Symbian
    Replies: 5
    Last Post: 2010-06-04, 07:56
  3. Replies: 19
    Last Post: 2008-05-24, 15:46
  4. how to save data in mobile memory in symbian c++
    By saugatapaul in forum Symbian
    Replies: 3
    Last Post: 2008-02-09, 17:57
  5. Replies: 1
    Last Post: 2003-08-20, 07:32

Posting Permissions

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