Colin, After your suggestion I decided to carefully review all the code… guess what… it was a typo!
Thanks for insisting! I feel stupid! :D Have a great weekend! Best regards, Nuno > On 15 Nov 2018, at 19:12, Nuno Santos <nunosan...@imaginando.pt> wrote: > > Yes, I can! The problem is when I close the app and start it again. The > result is null. > > Data is not being persisted and I do t understand why... :( > > -- > Nuno Santos > > No dia 15/11/2018, às 19:07, jlk <jlk2...@gmail.com > <mailto:jlk2...@gmail.com>> escreveu: > >> Hi Nuno, >> >> Can you save and restore a simple NSObject, say an NSString?. If so, your >> problem is probably with converting the QVariant to NSObject. I have not >> used Qt with iOS yet so I don't have any deeper help than that, sorry! >> However, Maybe there are helper functions you need to write first? Could >> you use a JSON converter to represent your QVariant as an (NS)string for >> storage? >> Colin >> >> On 11/15/18 1:31 PM, Nuno Santos wrote: >>> Colin, >>> >>> Thanks for your reply. >>> >>> While you are right considering the code I have posted here, the truth is >>> that in my actual code I have the setObject. But since I have more stuff >>> going on I didn’t want to flood the list with code: >>> >>> void Settings::setSharedKey(QString key, QVariant value) >>> { >>> if (defaults==nil) >>> defaults = [[NSUserDefaults alloc] >>> initWithSuiteName:@“group.com.acme.app"]; >>> >>> [defaults setObject:[ISettingsManagerCocoaHelper >>> variantToNSObject:value] forKey:key.toNSString()]; >>> [defaults synchronize]; >>> } >>> >>> I’m still struggling with this. I can’t have the settings saved. I’m tired >>> to googling and trying stuff. >>> >>> Any ideas? Do you have anything similar? >>> >>> Thanks! >>> >>> Regards, >>> >>> Nuno >>> >>>> On 15 Nov 2018, at 17:17, Colin Worth <jlk2...@gmail.com >>>> <mailto:jlk2...@gmail.com>> wrote: >>>> >>>> Hi Nuno, >>>> You are missing a line, something like: >>>> >>>> [defaults setValue:object forKey:key] >>>> >>>> in setSharedKey. >>>> >>>>> >>>>> From: Nuno Santos <nunosan...@imaginando.pt >>>>> <mailto:nunosan...@imaginando.pt>> >>>>> Subject: [Interest] Qt iOS / App Groups / NSUserDefaults >>>>> initWithSuiteName / Not persisting >>>>> Date: November 14, 2018 at 7:24:06 AM AST >>>>> To: "interest@qt-project.org <mailto:interest@qt-project.org> Interest" >>>>> <interest@qt-project.org <mailto:interest@qt-project.org>> >>>>> >>>>> >>>>> Hi, >>>>> >>>>> I’m trying to persist data in a App Group on Qt iOS app to share data >>>>> between a standalone app and app extension. >>>>> >>>>> I have been reading on how to do it and apparently is dead simple -> >>>>> https://developer.apple.com/library/archive/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html#//apple_ref/doc/uid/TP40014214-CH21-SW6 >>>>> >>>>> <https://developer.apple.com/library/archive/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html#//apple_ref/doc/uid/TP40014214-CH21-SW6> >>>>> >>>>> The problem is that it is not persisting data…. >>>>> >>>>> I’m starting to question the model I’m following in terms of code. I have >>>>> my Settings manager in C++. What I have done was to create a >>>>> SettingsCocoa.mm file that does what is below. >>>>> >>>>> In a app session, the value is persisted but as soon as I start the app >>>>> again, the value is null. >>>>> >>>>> As anyone experienced similar issues before? Any ideas would be highly >>>>> appreciated. >>>>> >>>>> Thanks in advance. >>>>> >>>>> Best regards, >>>>> >>>>> Nuno >>>>> >>>>> >>>>> #include "Settings.h" >>>>> >>>>> #import <Foundation/Foundation.h> >>>>> #include <QDebug> >>>>> >>>>> static NSUserDefaults *defaults = nil; >>>>> >>>>> QVariant Settings::sharedKey(QString key, const QVariant &defaultValue) >>>>> const >>>>> { >>>>> if (defaults==nil) >>>>> defaults = [[NSUserDefaults alloc] >>>>> initWithSuiteName:@"group.com.acme.app"]; >>>>> >>>>> NSObject *value = [defaults valueForKey:key.toNSString()]; >>>>> NSLog(@"get object: %@", value); >>>>> } >>>>> >>>>> void Settings::setSharedKey(QString key, QVariant value) >>>>> { >>>>> if (defaults==nil) >>>>> defaults = [[NSUserDefaults alloc] >>>>> initWithSuiteName:@"group.com.acme.app"]; >>>>> >>>>> NSObject *object = [ISettingsManagerCocoaHelper >>>>> variantToNSObject:value]; >>>>> NSLog(@"set object: %@", object); >>>>> >>>>> sharedKey(key, value); >>>>> >>>>> [defaults synchronize]; >>>>> } >>>>> >>> > _______________________________________________ > Interest mailing list > Interest@qt-project.org > http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest