Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
PrnvKP
Posts: 33
Registered: ‎01-31-2013
My Device: BlackBerry Z10 LE
My Carrier: Airtel
Accepted Solution

storing DateTime picker value in persistent memory

Hi all,

 

I am developing an application that  store certain settings in the persistent memory.I have managed to store certain text field entries and toggle control inputs using qsettings- (getValueFor and saveValueFor functions) but is unable to do so in the case of Datepicker as getValueFor returns qstring rather than QDateTime.

 

Alternatively I tried using settings.value() to to get the qstring value stored in the setting and use QDateTime::fromString to convert it to QDateTime format which can the be passed to the qml by QDeclarativePropertyMap but no success

 

my .cpp file-

 QDateTime date;
       QString dates=settings.value("userdob").toString();
       if(dates.isNull())
    	   //default value 
       QDateTime date=QDateTime::fromString("1980-01-22","YYYY-MM-DD");
       else{
        date = QDateTime::fromString(dates, "YYYY-MM-DD");}
       QDeclarativePropertyMap* settingparam =
               new QDeclarativePropertyMap;
       settingparam->insert("dates", date);
       qml->setContextProperty("userinfo", settingparam);


 .qml file-

                DateTimePicker {
                    id:userdob
                    objectName:"userdob"
                    title: "Date of Birth"
                    
                    value: userinfo.dates
                    translationY: -37.0
                        mode: DateTimePickerMode.Date
                     onValueChanged: {
                         app.saveValueFor(userdob.objectName,(userdob.value))
                     }

                    }

 

Can anyone please help me in getting this to work.

 

thank you,

Please use plain text.
Developer
simon_hain
Posts: 15,953
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: storing DateTime picker value in persistent memory

could you report what value you are trying to store and what value you retrieve?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
PrnvKP
Posts: 33
Registered: ‎01-31-2013
My Device: BlackBerry Z10 LE
My Carrier: Airtel

Re: storing DateTime picker value in persistent memory

I am trying to save the user's Date of Birth entered through a datepicker and store it in persistent memory so that next time the user access the page the datepicker should have value set as hi dob.

 

thankyou

Please use plain text.
Developer
simon_hain
Posts: 15,953
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: storing DateTime picker value in persistent memory

can you add logging to it and show us the console output?
like "storing 01.01.1970"
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
PrnvKP
Posts: 33
Registered: ‎01-31-2013
My Device: BlackBerry Z10 LE
My Carrier: Airtel

Re: storing DateTime picker value in persistent memory

I am unable to access my machine now but can you suggest any possible method for converting the Qstring value saved in Qsettings to QDateTime so that I can assign it as datetimepicker initial value

Please use plain text.
Developer
BBSJdev
Posts: 6,089
Registered: ‎07-05-2012
My Device: Playbook, Z10 LE, Dev Alpha C
My Carrier: Orange

Re: storing DateTime picker value in persistent memory

Sorry to butt in but why are you doing a conversion?

 

QSettings handles QVariant types directly, of which QDateTime is one.

 

http://qt-project.org/doc/qt-4.8/qvariant.html

 

So no conversion should be neccessary just pass the <DateTimePicker ID>.value directly to the C++ function handling your QSettings write.

 

 

 


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
Developer
PrnvKP
Posts: 33
Registered: ‎01-31-2013
My Device: BlackBerry Z10 LE
My Carrier: Airtel

Re: storing DateTime picker value in persistent memory

I am using the getValueFor(), setValueFor() method as in the statrshipsettings sample and it return a qstring
Please use plain text.
Developer
BBSJdev
Posts: 6,089
Registered: ‎07-05-2012
My Device: Playbook, Z10 LE, Dev Alpha C
My Carrier: Orange

Re: storing DateTime picker value in persistent memory

That's fine but I guess what I was suggesting is that you are making a lot of extra work for yourself by putting an unnecessary conversation in there. If all you want to do is save and reload a DateTimePicker then none of that is necessary.

 

If you need the string representation for something else then of course do it that way.

 


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
Developer
BBSJdev
Posts: 6,089
Registered: ‎07-05-2012
My Device: Playbook, Z10 LE, Dev Alpha C
My Carrier: Orange

Re: storing DateTime picker value in persistent memory

[ Edited ]

This for example is all you need to save a DateTime in persistent storage...

 

void SettingsHandler::persistentSave(QString key, QVariant data) {
    qDebug() << "Saving : " << key << data;
    qsPersistent.setValue(key, data);
}

 

DateTimePicker {
    id: pickerDate title: "Date (Persistent)"
    onValueChanged: {         settings.persistentSave("Date", pickerDate.value);
    }
    attachedObjects: [         SettingsHandler { id: settings }     ]
}

 


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
Developer
PrnvKP
Posts: 33
Registered: ‎01-31-2013
My Device: BlackBerry Z10 LE
My Carrier: Airtel

Re: storing DateTime picker value in persistent memory

Thanks very much guys. Indeed i was doing lot of useless conversion changed the function to store value as QVariants and it works
Please use plain text.