Discussion:
[Interest] Qt iOS / App Groups / NSUserDefaults initWithSuiteName / Not persisting (Nuno Santos)
Colin Worth
2018-11-15 17:17:49 UTC
Permalink
Hi Nuno,
You are missing a line, something like:

[defaults setValue:object forKey:key]

in setSharedKey.
Subject: [Interest] Qt iOS / App Groups / NSUserDefaults initWithSuiteName / Not persisting
Date: November 14, 2018 at 7:24:06 AM AST
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)
NSObject *value = [defaults valueForKey:key.toNSString()];
}
void Settings::setSharedKey(QString key, QVariant value)
{
if (defaults==nil)
NSObject *object = [ISettingsManagerCocoaHelper variantToNSObject:value];
sharedKey(key, value);
[defaults synchronize];
}
Subject: Re: [Interest] efficient natural sorting
Date: November 14, 2018 at 10:57:03 AM AST
Hi,
This works nicely but I’m wondering if it’s reliable and efficient to implement it like this in the QSortFilterProxyModel.lessThan() method?!
|def lessThan(self, source_left, source_right): natural_keys(source_left) < natural_keys(source_right) |
Any thoughts on this?
You can use QCollator to implement natural sorting (by enabling the numeric mode). Or doesn't it work for your use case?
My 2 c,
--
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts
Subject: Re: [Interest] efficient natural sorting
Date: November 14, 2018 at 11:14:21 AM AST
Hi,
I need to use the QSortFilterProxyModel to sort strings with numbers in them, i.e. perform natural sorting.
Another idea is to add a different role to your model, have data() return the original number (int or qreal or whatever) in the variant for that role, and call setSortRole() to tell QSFPM which role to use.
Subject: Re: [Interest] Connection problems with QNerworkAccessManager
Date: November 14, 2018 at 12:06:37 PM AST
No one?
I tried to copy the script outside of the htaccess restricted are, and it seems to work. Maybe it has todo with the combination of ssl and htaccess?
Regards
Hello,
i tried it with 5.11.x versions.
The log from the server shows that the request (which is a normal GET request), I also tried POST request, is sent a multiply of 100 per second so ~= 200 requests per second until the server give up.
I use https and a htaccess restricted area, which calls my authenticationRequired() slot.
Regards
have you tried 5.11.2, 5.12 Beta or 5.10.1 ?
Hi,
i use Qt 5.11.1 at the moment and have some connection problems with QNetworkAccessManager.
There are no error, sslerror or finished signals emitted, but I see the traffic in Wireshark.
The problem occurs on Windows, Mac and iOS.
When I enter the url in the browser, then it is working without a problem.
Any hints?
Thanks in advance
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
Subject: [Interest] Problem with font size on Android and High DPI
Date: November 14, 2018 at 12:11:13 PM AST
Hello everyone,
I enabled the High DPI option on an android tablet. However, the fonts are not resized at all and looks a way too small. I tried the other environment variables too, but the result is not as expected.
Does anyone have a hint or how is that done normally?
Regards
Roman
Subject: Re: [Interest] Problem with font size on Android and High DPI
Date: November 14, 2018 at 12:15:09 PM AST
Hello everyone,
I enabled the High DPI option on an android tablet. However, the fonts are not resized at all and looks a way too small. I tried the other environment variables too, but the result is not as expected.
Does anyone have a hint or how is that done normally?
Regards
Roman
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
what kind of application ?
QtQuickControls2 ?
ekke
Subject: Re: [Interest] Problem with font size on Android and High DPI
Date: November 14, 2018 at 12:29:36 PM AST
No, it is a QWidget application with Qt 5.12. I can’t switch to QtQuick because customer wants existing application to be ported to android tablet.
Regards
Roman
Hello everyone,
I enabled the High DPI option on an android tablet. However, the fonts are not resized at all and looks a way too small. I tried the other environment variables too, but the result is not as expected.
Does anyone have a hint or how is that done normally?
Regards
Roman
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
what kind of application ?
QtQuickControls2 ?
ekke
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
Subject: Re: [Interest] QDir::entry(Info)List on macos
Date: November 14, 2018 at 12:34:02 PM AST
int main() {
qDebug() << QDir(".").entryList();
QCoreApplication missing. Try again with it.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
Subject: Re: [Interest] Problem with font size on Android and High DPI
Date: November 14, 2018 at 1:17:27 PM AST
// Collect screen dimension
const QScreen* const screen = QGuiApplication::primaryScreen();
QRect rect = screen->geometry();
const qreal height = qMax(rect.width(), rect.height());
const qreal width = qMin(rect.width(), rect.height());
const qreal dpi = screen->logicalDotsPerInch();
// Compute reference ratio
m_horizontal_scale = width / REFERENCE_WIDTH;
m_vertical_scale = height / REFERENCE_HEIGHT;
m_dpi_scale = dpi / REFERENCE_DPI;
// Compute other element scale factor
m_font_scale = qMin(m_horizontal_scale / m_dpi_scale, m_vertical_scale / m_dpi_scale);
This allow you to have a display that look like each other compare to screen size. It's maybe not what yo are looking for but might give you some idea to achieve what you are looking for.
-----Original Message-----
Sent: November 14, 2018 11:30 AM
Subject: Re: [Interest] Problem with font size on Android and High DPI
No, it is a QWidget application with Qt 5.12. I can’t switch to QtQuick because customer wants existing application to be ported to android tablet.
Regards
Roman
Hello everyone,
I enabled the High DPI option on an android tablet. However, the fonts are not resized at all and looks a way too small. I tried the other environment variables too, but the result is not as expected.
Does anyone have a hint or how is that done normally?
Regards
Roman
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
what kind of application ?
QtQuickControls2 ?
ekke
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
Subject: Re: [Interest] Problem with font size on Android and High DPI
Date: November 14, 2018 at 2:32:06 PM AST
And then I need to go over all widgets and multiply the font scale with current font size?
Regards
// Collect screen dimension
const QScreen* const screen = QGuiApplication::primaryScreen();
QRect rect = screen->geometry();
const qreal height = qMax(rect.width(), rect.height());
const qreal width = qMin(rect.width(), rect.height());
const qreal dpi = screen->logicalDotsPerInch();
// Compute reference ratio
m_horizontal_scale = width / REFERENCE_WIDTH;
m_vertical_scale = height / REFERENCE_HEIGHT;
m_dpi_scale = dpi / REFERENCE_DPI;
// Compute other element scale factor
m_font_scale = qMin(m_horizontal_scale / m_dpi_scale, m_vertical_scale / m_dpi_scale);
This allow you to have a display that look like each other compare to screen size. It's maybe not what yo are looking for but might give you some idea to achieve what you are looking for.
-----Original Message-----
Sent: November 14, 2018 11:30 AM
Subject: Re: [Interest] Problem with font size on Android and High DPI
No, it is a QWidget application with Qt 5.12. I can’t switch to QtQuick because customer wants existing application to be ported to android tablet.
Regards
Roman
Hello everyone,
I enabled the High DPI option on an android tablet. However, the fonts are not resized at all and looks a way too small. I tried the other environment variables too, but the result is not as expected.
Does anyone have a hint or how is that done normally?
Regards
Roman
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
what kind of application ?
QtQuickControls2 ?
ekke
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
Subject: Re: [Interest] QDir::entry(Info)List on macos
Date: November 15, 2018 at 3:54:38 AM AST
int main() {
qDebug() << QDir(".").entryList();
QCoreApplication missing. Try again with it.
Tried, without success, still does not display these files. Even tried
with QDirIterator, that is also working the same (skipping these files).
With further checking I noticed that the files are only not displaying
if I do not create them with Qt. Eg I created with "touch filenamé". If
I create the same file with QFile, that seems to be found by these dir
lists. I know it sounds insane.
locale
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL="en_US.UTF-8"
cat main.cpp
#include <QDirIterator>
#include <QDebug>
#include <QFileInfoList>
#include <QCoreApplication>
#include <QFile>
int main(int argc, char** argv) {
QFile file("éáőú"); // This file is visible in the list! But not any
other I create with touch for example.
file.open(QFile::WriteOnly);
file.close();
QCoreApplication app(argc, argv);
QDirIterator iterator(".", QDir::Files, QDirIterator::Subdirectories);
while (iterator.hasNext())
{
qDebug() << "QDiriterator" << iterator.next();
}
qDebug() << QDir(".").entryList(QDir::System | QDir::AllEntries |
QDir::Hidden);
qDebug() << QDir(".").entryInfoList(QDir::System | QDir::AllEntries |
QDir::Hidden);
}
Thanks in advance for any idea.
Robert
Subject: Re: [Interest] QDir::entry(Info)List on macos
Date: November 15, 2018 at 4:49:08 AM AST
What is the encoding of your source file?
QString constructors interprets char* as if they are UTF-8. If the
source file is encoded in your local encoding, the QString created for
QFile constructor will have a wrong unicode storage of your wanted
filename, then will try to convert what it thinks is UTF into your
local encoding to pass the filename to the system calls. Maybe the mac
explorer can work around this and adjust the displayed name, but the
Filesystem interface of Qt can't because that puts forbidden
characters in the real name?
int main() {
qDebug() << QDir(".").entryList();
QCoreApplication missing. Try again with it.
Tried, without success, still does not display these files. Even tried
with QDirIterator, that is also working the same (skipping these files).
With further checking I noticed that the files are only not displaying
if I do not create them with Qt. Eg I created with "touch filenamé". If
I create the same file with QFile, that seems to be found by these dir
lists. I know it sounds insane.
locale
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL="en_US.UTF-8"
cat main.cpp
#include <QDirIterator>
#include <QDebug>
#include <QFileInfoList>
#include <QCoreApplication>
#include <QFile>
int main(int argc, char** argv) {
QFile file("éáőú"); // This file is visible in the list! But not any
other I create with touch for example.
file.open(QFile::WriteOnly);
file.close();
QCoreApplication app(argc, argv);
QDirIterator iterator(".", QDir::Files, QDirIterator::Subdirectories);
while (iterator.hasNext())
{
qDebug() << "QDiriterator" << iterator.next();
}
qDebug() << QDir(".").entryList(QDir::System | QDir::AllEntries |
QDir::Hidden);
qDebug() << QDir(".").entryInfoList(QDir::System | QDir::AllEntries |
QDir::Hidden);
}
Thanks in advance for any idea.
Robert
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
Subject: Re: [Interest] QDir::entry(Info)List on macos
Date: November 15, 2018 at 9:54:22 AM AST
Hi,
((
file main.cpp
main.cpp: c program text, UTF-8 Unicode text
))
https://bugreports.qt.io/browse/QTBUG-70732
I am currently working on a workaround, I am now able to list the files
QStringList results;
DIR *dir;
struct dirent *ent;
QByteArray bpath = path.toUtf8();
if ((dir = opendir (bpath.constData())) != NULL) {
/* print all the files and directories within directory */
while ((ent = readdir (dir)) != NULL) {
results << ent->d_name;
}
closedir (dir);
} else {
/* could not open directory */
perror ("");
}
return results;
This gives back the files successfully, the downside is that they are in
UTF-8 normalization format D (UTF-8-mac) which represents accented
characters like O" format, so the original character (O) + the accent
("). Similarly as "ls -1" does.
And having a QString like that does not match "normal" (==
QString ch1("\u00D6"); // this is normal representation of "Ö"
QString ch2("O\u0308"); // this specifies O with an accent
qDebug() << ch1 << ch2 << (ch1 == ch2 ? "matches!" : "does not match");
This outputs: "Ö" "Ö" "does not match" not only on mac, but even on linux.
So I also needed to convert "utf8 to utf8" :) for my complete
workaround. Unfortunately I did not find a way to do so with QTextCodec.
(Is there?) So I am trying now iconv... this seems to do the trick, but
quite ugly and inefficient.
QByteArray
utf8_unmac(const QByteArray &utf8_mac)
{
iconv_t conv = iconv_open("UTF-8-mac", "UTF-8");
if (conv == (iconv_t)-1)
{
RAISE(TestRunnerException(QString("Iconv open failed: ") +
sys_errlist[errno]));
}
char *inp = const_cast<char *>(utf8_mac.constData()); // iconv is
moving these thats why the duplication
size_t inp_len = utf8_mac.size();
size_t out_len = inp_len * 2;
QByteArray utf8;
utf8.resize(out_len);
char *out = utf8.data();
if (iconv(conv, &inp, &inp_len, &out, &out_len) == (size_t)-1)
{
RAISE(TestRunnerException(QString("Iconv convert failed: ") +
sys_errlist[errno]));
}
utf8.chop(out_len);
iconv_close(conv);
return utf8;
}
Hope it is useful for someone. To be honest, I always imagined that if
everyone would use UTF-8 life would be much better, now I'm unsure ;)
Br,
Robert
What is the encoding of your source file?
QString constructors interprets char* as if they are UTF-8. If the
source file is encoded in your local encoding, the QString created for
QFile constructor will have a wrong unicode storage of your wanted
filename, then will try to convert what it thinks is UTF into your
local encoding to pass the filename to the system calls. Maybe the mac
explorer can work around this and adjust the displayed name, but the
Filesystem interface of Qt can't because that puts forbidden
characters in the real name?
int main() {
qDebug() << QDir(".").entryList();
QCoreApplication missing. Try again with it.
Tried, without success, still does not display these files. Even tried
with QDirIterator, that is also working the same (skipping these files).
With further checking I noticed that the files are only not displaying
if I do not create them with Qt. Eg I created with "touch filenamé". If
I create the same file with QFile, that seems to be found by these dir
lists. I know it sounds insane.
locale
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL="en_US.UTF-8"
cat main.cpp
#include <QDirIterator>
#include <QDebug>
#include <QFileInfoList>
#include <QCoreApplication>
#include <QFile>
int main(int argc, char** argv) {
QFile file("éáőú"); // This file is visible in the list! But not any
other I create with touch for example.
file.open(QFile::WriteOnly);
file.close();
QCoreApplication app(argc, argv);
QDirIterator iterator(".", QDir::Files, QDirIterator::Subdirectories);
while (iterator.hasNext())
{
qDebug() << "QDiriterator" << iterator.next();
}
qDebug() << QDir(".").entryList(QDir::System | QDir::AllEntries |
QDir::Hidden);
qDebug() << QDir(".").entryInfoList(QDir::System | QDir::AllEntries |
QDir::Hidden);
}
Thanks in advance for any idea.
Robert
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
Subject: Re: [Interest] Problem with font size on Android and High DPI
Date: November 15, 2018 at 10:42:20 AM AST
That I don't known, I'm 100% Qml and I just apply this to my Control style at one place. Maybe there is a way to do this into the cascading widget style...
-----Original Message-----
Sent: November 14, 2018 1:32 PM
Subject: Re: [Interest] Problem with font size on Android and High DPI
And then I need to go over all widgets and multiply the font scale with current font size?
Regards
// Collect screen dimension
const QScreen* const screen = QGuiApplication::primaryScreen();
QRect rect = screen->geometry();
const qreal height = qMax(rect.width(), rect.height());
const qreal width = qMin(rect.width(), rect.height());
const qreal dpi = screen->logicalDotsPerInch();
// Compute reference ratio
m_horizontal_scale = width / REFERENCE_WIDTH;
m_vertical_scale = height / REFERENCE_HEIGHT;
m_dpi_scale = dpi / REFERENCE_DPI;
// Compute other element scale factor
m_font_scale = qMin(m_horizontal_scale / m_dpi_scale, m_vertical_scale / m_dpi_scale);
This allow you to have a display that look like each other compare to screen size. It's maybe not what yo are looking for but might give you some idea to achieve what you are looking for.
-----Original Message-----
Sent: November 14, 2018 11:30 AM
Subject: Re: [Interest] Problem with font size on Android and High DPI
No, it is a QWidget application with Qt 5.12. I can’t switch to QtQuick because customer wants existing application to be ported to android tablet.
Regards
Roman
Hello everyone,
I enabled the High DPI option on an android tablet. However, the fonts are not resized at all and looks a way too small. I tried the other environment variables too, but the result is not as expected.
Does anyone have a hint or how is that done normally?
Regards
Roman
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
what kind of application ?
QtQuickControls2 ?
ekke
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
Subject: Re: [Interest] Problem with font size on Android and High DPI
Date: November 15, 2018 at 11:04:41 AM AST
QGuiApplication app(argc, argv);
QScreen *screen = app.screens()[0];
double dpi = screen->physicalDotsPerInch();
dpi-= dpi * 10/100;
if(dpi >= 640) dpi = dpi/640; //xxxhdpi
else if (dpi >= 480) dpi = dpi/480; //xxhdpi
else if (dpi >= 320) dpi = dpi/320; //xhdpi
else if (dpi >= 240) dpi = dpi/240; //hdpi
else if (dpi >= 160) dpi = dpi/160; //mdpi
else if (dpi >= 120) dpi = dpi/120; //ldpi
else{
dpi = 1;//ldpi
}
I used as above then multiply all font pixels with "dpi".
That I don't known, I'm 100% Qml and I just apply this to my Control style at one place. Maybe there is a way to do this into the cascading widget style...
-----Original Message-----
Sent: November 14, 2018 1:32 PM
Subject: Re: [Interest] Problem with font size on Android and High DPI
And then I need to go over all widgets and multiply the font scale with current font size?
Regards
// Collect screen dimension
const QScreen* const screen = QGuiApplication::primaryScreen();
QRect rect = screen->geometry();
const qreal height = qMax(rect.width(), rect.height());
const qreal width = qMin(rect.width(), rect.height());
const qreal dpi = screen->logicalDotsPerInch();
// Compute reference ratio
m_horizontal_scale = width / REFERENCE_WIDTH;
m_vertical_scale = height / REFERENCE_HEIGHT;
m_dpi_scale = dpi / REFERENCE_DPI;
// Compute other element scale factor
m_font_scale = qMin(m_horizontal_scale / m_dpi_scale, m_vertical_scale / m_dpi_scale);
This allow you to have a display that look like each other compare to screen size. It's maybe not what yo are looking for but might give you some idea to achieve what you are looking for.
-----Original Message-----
Sent: November 14, 2018 11:30 AM
Subject: Re: [Interest] Problem with font size on Android and High DPI
No, it is a QWidget application with Qt 5.12. I can’t switch to QtQuick because customer wants existing application to be ported to android tablet.
Regards
Roman
Hello everyone,
I enabled the High DPI option on an android tablet. However, the fonts are not resized at all and looks a way too small. I tried the other environment variables too, but the result is not as expected.
Does anyone have a hint or how is that done normally?
Regards
Roman
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest <http://lists.qt-project.org/mailman/listinfo/interest>
what kind of application ?
QtQuickControls2 ?
ekke
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest <http://lists.qt-project.org/mailman/listinfo/interest>
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest <http://lists.qt-project.org/mailman/listinfo/interest>
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest <http://lists.qt-project.org/mailman/listinfo/interest>
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
Nuno Santos
2018-11-15 18:31:14 UTC
Permalink
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
Post by Colin Worth
Hi Nuno,
[defaults setValue:object forKey:key]
in setSharedKey.
Subject: [Interest] Qt iOS / App Groups / NSUserDefaults initWithSuiteName / Not persisting
Date: November 14, 2018 at 7:24:06 AM AST
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)
NSObject *value = [defaults valueForKey:key.toNSString()];
}
void Settings::setSharedKey(QString key, QVariant value)
{
if (defaults==nil)
NSObject *object = [ISettingsManagerCocoaHelper variantToNSObject:value];
sharedKey(key, value);
[defaults synchronize];
}
Subject: Re: [Interest] efficient natural sorting
Date: November 14, 2018 at 10:57:03 AM AST
Hi,
This works nicely but I’m wondering if it’s reliable and efficient to implement it like this in the QSortFilterProxyModel.lessThan() method?!
|def lessThan(self, source_left, source_right): natural_keys(source_left) < natural_keys(source_right) |
Any thoughts on this?
You can use QCollator to implement natural sorting (by enabling the numeric mode). Or doesn't it work for your use case?
My 2 c,
--
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com <http://www.kdab.com/>
KDAB - The Qt, C++ and OpenGL Experts
Subject: Re: [Interest] efficient natural sorting
Date: November 14, 2018 at 11:14:21 AM AST
Hi,
I need to use the QSortFilterProxyModel to sort strings with numbers in them, i.e. perform natural sorting.
Another idea is to add a different role to your model, have data() return the original number (int or qreal or whatever) in the variant for that role, and call setSortRole() to tell QSFPM which role to use.
Subject: Re: [Interest] Connection problems with QNerworkAccessManager
Date: November 14, 2018 at 12:06:37 PM AST
No one?
I tried to copy the script outside of the htaccess restricted are, and it seems to work. Maybe it has todo with the combination of ssl and htaccess?
Regards
Hello,
i tried it with 5.11.x versions.
The log from the server shows that the request (which is a normal GET request), I also tried POST request, is sent a multiply of 100 per second so ~= 200 requests per second until the server give up.
I use https and a htaccess restricted area, which calls my authenticationRequired() slot.
Regards
have you tried 5.11.2, 5.12 Beta or 5.10.1 ?
Hi,
i use Qt 5.11.1 at the moment and have some connection problems with QNetworkAccessManager.
There are no error, sslerror or finished signals emitted, but I see the traffic in Wireshark.
The problem occurs on Windows, Mac and iOS.
When I enter the url in the browser, then it is working without a problem.
Any hints?
Thanks in advance
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
Subject: [Interest] Problem with font size on Android and High DPI
Date: November 14, 2018 at 12:11:13 PM AST
Hello everyone,
I enabled the High DPI option on an android tablet. However, the fonts are not resized at all and looks a way too small. I tried the other environment variables too, but the result is not as expected.
Does anyone have a hint or how is that done normally?
Regards
Roman
Subject: Re: [Interest] Problem with font size on Android and High DPI
Date: November 14, 2018 at 12:15:09 PM AST
Hello everyone,
I enabled the High DPI option on an android tablet. However, the fonts are not resized at all and looks a way too small. I tried the other environment variables too, but the result is not as expected.
Does anyone have a hint or how is that done normally?
Regards
Roman
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
what kind of application ?
QtQuickControls2 ?
ekke
Subject: Re: [Interest] Problem with font size on Android and High DPI
Date: November 14, 2018 at 12:29:36 PM AST
No, it is a QWidget application with Qt 5.12. I can’t switch to QtQuick because customer wants existing application to be ported to android tablet.
Regards
Roman
Hello everyone,
I enabled the High DPI option on an android tablet. However, the fonts are not resized at all and looks a way too small. I tried the other environment variables too, but the result is not as expected.
Does anyone have a hint or how is that done normally?
Regards
Roman
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
what kind of application ?
QtQuickControls2 ?
ekke
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
Subject: Re: [Interest] QDir::entry(Info)List on macos
Date: November 14, 2018 at 12:34:02 PM AST
int main() {
qDebug() << QDir(".").entryList();
QCoreApplication missing. Try again with it.
--
Thiago Macieira - thiago.macieira (AT) intel.com <http://intel.com/>
Software Architect - Intel Open Source Technology Center
Subject: Re: [Interest] Problem with font size on Android and High DPI
Date: November 14, 2018 at 1:17:27 PM AST
// Collect screen dimension
const QScreen* const screen = QGuiApplication::primaryScreen();
QRect rect = screen->geometry();
const qreal height = qMax(rect.width(), rect.height());
const qreal width = qMin(rect.width(), rect.height());
const qreal dpi = screen->logicalDotsPerInch();
// Compute reference ratio
m_horizontal_scale = width / REFERENCE_WIDTH;
m_vertical_scale = height / REFERENCE_HEIGHT;
m_dpi_scale = dpi / REFERENCE_DPI;
// Compute other element scale factor
m_font_scale = qMin(m_horizontal_scale / m_dpi_scale, m_vertical_scale / m_dpi_scale);
This allow you to have a display that look like each other compare to screen size. It's maybe not what yo are looking for but might give you some idea to achieve what you are looking for.
-----Original Message-----
Sent: November 14, 2018 11:30 AM
Subject: Re: [Interest] Problem with font size on Android and High DPI
No, it is a QWidget application with Qt 5.12. I can’t switch to QtQuick because customer wants existing application to be ported to android tablet.
Regards
Roman
Hello everyone,
I enabled the High DPI option on an android tablet. However, the fonts are not resized at all and looks a way too small. I tried the other environment variables too, but the result is not as expected.
Does anyone have a hint or how is that done normally?
Regards
Roman
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
what kind of application ?
QtQuickControls2 ?
ekke
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
Subject: Re: [Interest] Problem with font size on Android and High DPI
Date: November 14, 2018 at 2:32:06 PM AST
And then I need to go over all widgets and multiply the font scale with current font size?
Regards
// Collect screen dimension
const QScreen* const screen = QGuiApplication::primaryScreen();
QRect rect = screen->geometry();
const qreal height = qMax(rect.width(), rect.height());
const qreal width = qMin(rect.width(), rect.height());
const qreal dpi = screen->logicalDotsPerInch();
// Compute reference ratio
m_horizontal_scale = width / REFERENCE_WIDTH;
m_vertical_scale = height / REFERENCE_HEIGHT;
m_dpi_scale = dpi / REFERENCE_DPI;
// Compute other element scale factor
m_font_scale = qMin(m_horizontal_scale / m_dpi_scale, m_vertical_scale / m_dpi_scale);
This allow you to have a display that look like each other compare to screen size. It's maybe not what yo are looking for but might give you some idea to achieve what you are looking for.
-----Original Message-----
Sent: November 14, 2018 11:30 AM
Subject: Re: [Interest] Problem with font size on Android and High DPI
No, it is a QWidget application with Qt 5.12. I can’t switch to QtQuick because customer wants existing application to be ported to android tablet.
Regards
Roman
Hello everyone,
I enabled the High DPI option on an android tablet. However, the fonts are not resized at all and looks a way too small. I tried the other environment variables too, but the result is not as expected.
Does anyone have a hint or how is that done normally?
Regards
Roman
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
what kind of application ?
QtQuickControls2 ?
ekke
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
Subject: Re: [Interest] QDir::entry(Info)List on macos
Date: November 15, 2018 at 3:54:38 AM AST
int main() {
qDebug() << QDir(".").entryList();
QCoreApplication missing. Try again with it.
Tried, without success, still does not display these files. Even tried
with QDirIterator, that is also working the same (skipping these files).
With further checking I noticed that the files are only not displaying
if I do not create them with Qt. Eg I created with "touch filenamé". If
I create the same file with QFile, that seems to be found by these dir
lists. I know it sounds insane.
locale
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL="en_US.UTF-8"
cat main.cpp
#include <QDirIterator>
#include <QDebug>
#include <QFileInfoList>
#include <QCoreApplication>
#include <QFile>
int main(int argc, char** argv) {
QFile file("éáőú"); // This file is visible in the list! But not any
other I create with touch for example.
file.open(QFile::WriteOnly);
file.close();
QCoreApplication app(argc, argv);
QDirIterator iterator(".", QDir::Files, QDirIterator::Subdirectories);
while (iterator.hasNext())
{
qDebug() << "QDiriterator" << iterator.next();
}
qDebug() << QDir(".").entryList(QDir::System | QDir::AllEntries |
QDir::Hidden);
qDebug() << QDir(".").entryInfoList(QDir::System | QDir::AllEntries |
QDir::Hidden);
}
Thanks in advance for any idea.
Robert
Subject: Re: [Interest] QDir::entry(Info)List on macos
Date: November 15, 2018 at 4:49:08 AM AST
What is the encoding of your source file?
QString constructors interprets char* as if they are UTF-8. If the
source file is encoded in your local encoding, the QString created for
QFile constructor will have a wrong unicode storage of your wanted
filename, then will try to convert what it thinks is UTF into your
local encoding to pass the filename to the system calls. Maybe the mac
explorer can work around this and adjust the displayed name, but the
Filesystem interface of Qt can't because that puts forbidden
characters in the real name?
int main() {
qDebug() << QDir(".").entryList();
QCoreApplication missing. Try again with it.
Tried, without success, still does not display these files. Even tried
with QDirIterator, that is also working the same (skipping these files).
With further checking I noticed that the files are only not displaying
if I do not create them with Qt. Eg I created with "touch filenamé". If
I create the same file with QFile, that seems to be found by these dir
lists. I know it sounds insane.
locale
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL="en_US.UTF-8"
cat main.cpp
#include <QDirIterator>
#include <QDebug>
#include <QFileInfoList>
#include <QCoreApplication>
#include <QFile>
int main(int argc, char** argv) {
QFile file("éáőú"); // This file is visible in the list! But not any
other I create with touch for example.
file.open(QFile::WriteOnly);
file.close();
QCoreApplication app(argc, argv);
QDirIterator iterator(".", QDir::Files, QDirIterator::Subdirectories);
while (iterator.hasNext())
{
qDebug() << "QDiriterator" << iterator.next();
}
qDebug() << QDir(".").entryList(QDir::System | QDir::AllEntries |
QDir::Hidden);
qDebug() << QDir(".").entryInfoList(QDir::System | QDir::AllEntries |
QDir::Hidden);
}
Thanks in advance for any idea.
Robert
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
Subject: Re: [Interest] QDir::entry(Info)List on macos
Date: November 15, 2018 at 9:54:22 AM AST
Hi,
((
file main.cpp
main.cpp: c program text, UTF-8 Unicode text
))
https://bugreports.qt.io/browse/QTBUG-70732
I am currently working on a workaround, I am now able to list the files
QStringList results;
DIR *dir;
struct dirent *ent;
QByteArray bpath = path.toUtf8();
if ((dir = opendir (bpath.constData())) != NULL) {
/* print all the files and directories within directory */
while ((ent = readdir (dir)) != NULL) {
results << ent->d_name;
}
closedir (dir);
} else {
/* could not open directory */
perror ("");
}
return results;
This gives back the files successfully, the downside is that they are in
UTF-8 normalization format D (UTF-8-mac) which represents accented
characters like O" format, so the original character (O) + the accent
("). Similarly as "ls -1" does.
And having a QString like that does not match "normal" (==
QString ch1("\u00D6"); // this is normal representation of "Ö"
QString ch2("O\u0308"); // this specifies O with an accent
qDebug() << ch1 << ch2 << (ch1 == ch2 ? "matches!" : "does not match");
This outputs: "Ö" "Ö" "does not match" not only on mac, but even on linux.
So I also needed to convert "utf8 to utf8" :) for my complete
workaround. Unfortunately I did not find a way to do so with QTextCodec.
(Is there?) So I am trying now iconv... this seems to do the trick, but
quite ugly and inefficient.
QByteArray
utf8_unmac(const QByteArray &utf8_mac)
{
iconv_t conv = iconv_open("UTF-8-mac", "UTF-8");
if (conv == (iconv_t)-1)
{
RAISE(TestRunnerException(QString("Iconv open failed: ") +
sys_errlist[errno]));
}
char *inp = const_cast<char *>(utf8_mac.constData()); // iconv is
moving these thats why the duplication
size_t inp_len = utf8_mac.size();
size_t out_len = inp_len * 2;
QByteArray utf8;
utf8.resize(out_len);
char *out = utf8.data();
if (iconv(conv, &inp, &inp_len, &out, &out_len) == (size_t)-1)
{
RAISE(TestRunnerException(QString("Iconv convert failed: ") +
sys_errlist[errno]));
}
utf8.chop(out_len);
iconv_close(conv);
return utf8;
}
Hope it is useful for someone. To be honest, I always imagined that if
everyone would use UTF-8 life would be much better, now I'm unsure ;)
Br,
Robert
What is the encoding of your source file?
QString constructors interprets char* as if they are UTF-8. If the
source file is encoded in your local encoding, the QString created for
QFile constructor will have a wrong unicode storage of your wanted
filename, then will try to convert what it thinks is UTF into your
local encoding to pass the filename to the system calls. Maybe the mac
explorer can work around this and adjust the displayed name, but the
Filesystem interface of Qt can't because that puts forbidden
characters in the real name?
int main() {
qDebug() << QDir(".").entryList();
QCoreApplication missing. Try again with it.
Tried, without success, still does not display these files. Even tried
with QDirIterator, that is also working the same (skipping these files).
With further checking I noticed that the files are only not displaying
if I do not create them with Qt. Eg I created with "touch filenamé". If
I create the same file with QFile, that seems to be found by these dir
lists. I know it sounds insane.
locale
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL="en_US.UTF-8"
cat main.cpp
#include <QDirIterator>
#include <QDebug>
#include <QFileInfoList>
#include <QCoreApplication>
#include <QFile>
int main(int argc, char** argv) {
QFile file("éáőú"); // This file is visible in the list! But not any
other I create with touch for example.
file.open(QFile::WriteOnly);
file.close();
QCoreApplication app(argc, argv);
QDirIterator iterator(".", QDir::Files, QDirIterator::Subdirectories);
while (iterator.hasNext())
{
qDebug() << "QDiriterator" << iterator.next();
}
qDebug() << QDir(".").entryList(QDir::System | QDir::AllEntries |
QDir::Hidden);
qDebug() << QDir(".").entryInfoList(QDir::System | QDir::AllEntries |
QDir::Hidden);
}
Thanks in advance for any idea.
Robert
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
Subject: Re: [Interest] Problem with font size on Android and High DPI
Date: November 15, 2018 at 10:42:20 AM AST
That I don't known, I'm 100% Qml and I just apply this to my Control style at one place. Maybe there is a way to do this into the cascading widget style...
-----Original Message-----
Sent: November 14, 2018 1:32 PM
Subject: Re: [Interest] Problem with font size on Android and High DPI
And then I need to go over all widgets and multiply the font scale with current font size?
Regards
// Collect screen dimension
const QScreen* const screen = QGuiApplication::primaryScreen();
QRect rect = screen->geometry();
const qreal height = qMax(rect.width(), rect.height());
const qreal width = qMin(rect.width(), rect.height());
const qreal dpi = screen->logicalDotsPerInch();
// Compute reference ratio
m_horizontal_scale = width / REFERENCE_WIDTH;
m_vertical_scale = height / REFERENCE_HEIGHT;
m_dpi_scale = dpi / REFERENCE_DPI;
// Compute other element scale factor
m_font_scale = qMin(m_horizontal_scale / m_dpi_scale, m_vertical_scale / m_dpi_scale);
This allow you to have a display that look like each other compare to screen size. It's maybe not what yo are looking for but might give you some idea to achieve what you are looking for.
-----Original Message-----
Sent: November 14, 2018 11:30 AM
Subject: Re: [Interest] Problem with font size on Android and High DPI
No, it is a QWidget application with Qt 5.12. I can’t switch to QtQuick because customer wants existing application to be ported to android tablet.
Regards
Roman
Hello everyone,
I enabled the High DPI option on an android tablet. However, the fonts are not resized at all and looks a way too small. I tried the other environment variables too, but the result is not as expected.
Does anyone have a hint or how is that done normally?
Regards
Roman
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
what kind of application ?
QtQuickControls2 ?
ekke
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
Subject: Re: [Interest] Problem with font size on Android and High DPI
Date: November 15, 2018 at 11:04:41 AM AST
QGuiApplication app(argc, argv);
QScreen *screen = app.screens()[0];
double dpi = screen->physicalDotsPerInch();
dpi-= dpi * 10/100;
if(dpi >= 640) dpi = dpi/640; //xxxhdpi
else if (dpi >= 480) dpi = dpi/480; //xxhdpi
else if (dpi >= 320) dpi = dpi/320; //xhdpi
else if (dpi >= 240) dpi = dpi/240; //hdpi
else if (dpi >= 160) dpi = dpi/160; //mdpi
else if (dpi >= 120) dpi = dpi/120; //ldpi
else{
dpi = 1;//ldpi
}
I used as above then multiply all font pixels with "dpi".
That I don't known, I'm 100% Qml and I just apply this to my Control style at one place. Maybe there is a way to do this into the cascading widget style...
-----Original Message-----
Sent: November 14, 2018 1:32 PM
Subject: Re: [Interest] Problem with font size on Android and High DPI
And then I need to go over all widgets and multiply the font scale with current font size?
Regards
// Collect screen dimension
const QScreen* const screen = QGuiApplication::primaryScreen();
QRect rect = screen->geometry();
const qreal height = qMax(rect.width(), rect.height());
const qreal width = qMin(rect.width(), rect.height());
const qreal dpi = screen->logicalDotsPerInch();
// Compute reference ratio
m_horizontal_scale = width / REFERENCE_WIDTH;
m_vertical_scale = height / REFERENCE_HEIGHT;
m_dpi_scale = dpi / REFERENCE_DPI;
// Compute other element scale factor
m_font_scale = qMin(m_horizontal_scale / m_dpi_scale, m_vertical_scale / m_dpi_scale);
This allow you to have a display that look like each other compare to screen size. It's maybe not what yo are looking for but might give you some idea to achieve what you are looking for.
-----Original Message-----
Sent: November 14, 2018 11:30 AM
Subject: Re: [Interest] Problem with font size on Android and High DPI
No, it is a QWidget application with Qt 5.12. I can’t switch to QtQuick because customer wants existing application to be ported to android tablet.
Regards
Roman
Hello everyone,
I enabled the High DPI option on an android tablet. However, the fonts are not resized at all and looks a way too small. I tried the other environment variables too, but the result is not as expected.
Does anyone have a hint or how is that done normally?
Regards
Roman
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest <http://lists.qt-project.org/mailman/listinfo/interest>
what kind of application ?
QtQuickControls2 ?
ekke
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest <http://lists.qt-project.org/mailman/listinfo/interest>
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest <http://lists.qt-project.org/mailman/listinfo/interest>
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest <http://lists.qt-project.org/mailman/listinfo/interest>
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
jlk
2018-11-15 19:07:07 UTC
Permalink
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
Post by Nuno Santos
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
void Settings::setSharedKey(QString key, QVariant value)
{
    if (defaults==nil)
        defaults = [[NSUserDefaults alloc]
    [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
Post by Colin Worth
Hi Nuno,
   [defaults setValue:object forKey:key]
in setSharedKey.
*Subject: **[Interest] Qt iOS / App Groups / NSUserDefaults
initWithSuiteName / Not persisting*
*Date: *November 14, 2018 at 7:24:06 AM AST
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
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]
*    NSObject *value = [defaults valueForKey:key.toNSString()];*
*}*
*
*
*void Settings::setSharedKey(QString key, QVariant value)*
*{*
*    if (defaults==nil)*
*        defaults = [[NSUserDefaults alloc]
*
*
*    NSObject *object = [ISettingsManagerCocoaHelper
variantToNSObject:value];*
*
*
*    sharedKey(key, value);*
*
*
*    [defaults synchronize];*
*}*
Nuno Santos
2018-11-15 19:12:55 UTC
Permalink
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
Post by Colin Worth
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
Post by Nuno Santos
Colin,
Thanks for your reply.
void Settings::setSharedKey(QString key, QVariant value)
{
if (defaults==nil)
[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
Post by Colin Worth
Hi Nuno,
[defaults setValue:object forKey:key]
in setSharedKey.
Subject: [Interest] Qt iOS / App Groups / NSUserDefaults initWithSuiteName / Not persisting
Date: November 14, 2018 at 7:24:06 AM AST
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
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)
NSObject *value = [defaults valueForKey:key.toNSString()];
}
void Settings::setSharedKey(QString key, QVariant value)
{
if (defaults==nil)
NSObject *object = [ISettingsManagerCocoaHelper variantToNSObject:value];
sharedKey(key, value);
[defaults synchronize];
}
Nuno Santos
2018-11-16 17:30:53 UTC
Permalink
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
Post by Nuno Santos
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
Post by Colin Worth
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
Post by Nuno Santos
Colin,
Thanks for your reply.
void Settings::setSharedKey(QString key, QVariant value)
{
if (defaults==nil)
[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
Post by Colin Worth
Hi Nuno,
[defaults setValue:object forKey:key]
in setSharedKey.
Subject: [Interest] Qt iOS / App Groups / NSUserDefaults initWithSuiteName / Not persisting
Date: November 14, 2018 at 7:24:06 AM AST
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)
NSObject *value = [defaults valueForKey:key.toNSString()];
}
void Settings::setSharedKey(QString key, QVariant value)
{
if (defaults==nil)
NSObject *object = [ISettingsManagerCocoaHelper variantToNSObject:value];
sharedKey(key, value);
[defaults synchronize];
}
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
John Weeks
2018-11-16 18:02:54 UTC
Permalink
Post by Nuno Santos
I feel stupid! :D
Heh. You can join the elite group of, what, nearly 100% of coders who have had this experience? :)

Those that haven't are probably not doing serious work.

-John Weeks
WaveMetrics, Inc.

Loading...