[Interest] Qt iOS / App Groups / NSUserDefaults initWithSuiteName / Not persisting (Nuno Santos)

Nuno Santos nunosantos at imaginando.pt
Thu Nov 15 19:31:14 CET 2018


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 <jlk2144 at gmail.com> wrote:
> 
> Hi Nuno,
>    You are missing a line, something like:
> 
>    [defaults setValue:object forKey:key]
> 
> in setSharedKey.
> 
>> 
>> From: Nuno Santos <nunosantos at imaginando.pt <mailto:nunosantos at imaginando.pt>>
>> Subject: [Interest] Qt iOS / App Groups / NSUserDefaults initWithSuiteName / Not persisting
>> Date: November 14, 2018 at 7:24:06 AM AST
>> To: "interest at qt-project.org <mailto:interest at qt-project.org> Interest" <interest at qt-project.org <mailto:interest at 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];
>> }
>> 
>> 
>> 
>> From: Giuseppe D'Angelo <giuseppe.dangelo at kdab.com <mailto:giuseppe.dangelo at kdab.com>>
>> Subject: Re: [Interest] efficient natural sorting
>> Date: November 14, 2018 at 10:57:03 AM AST
>> To: interest at qt-project.org <mailto:interest at qt-project.org>
>> 
>> 
>> Hi,
>> 
>> Il 14/11/18 03:28, Frank Rueter | OHUfx ha scritto:
>>> 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,
>> -- 
>> Giuseppe D'Angelo | giuseppe.dangelo at kdab.com <mailto:giuseppe.dangelo at kdab.com> | Senior Software Engineer
>> 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
>> 
>> 
>> 
>> 
>> From: Shawn Rutledge <Shawn.Rutledge at qt.io <mailto:Shawn.Rutledge at qt.io>>
>> Subject: Re: [Interest] efficient natural sorting
>> Date: November 14, 2018 at 11:14:21 AM AST
>> To: "interest at qt-project.org <mailto:interest at qt-project.org>" <interest at qt-project.org <mailto:interest at qt-project.org>>
>> 
>> 
>> 
>>> On 14 Nov 2018, at 03:28, Frank Rueter | OHUfx <frank at ohufx.com <mailto:frank at ohufx.com>> wrote:
>>> 
>>> 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.
>> 
>> 
>> 
>> 
>> 
>> From: Roman Wüger <roman.wueger at gmx.at <mailto:roman.wueger at gmx.at>>
>> Subject: Re: [Interest] Connection problems with QNerworkAccessManager
>> Date: November 14, 2018 at 12:06:37 PM AST
>> To: ekke <ekke at ekkes-corner.org <mailto:ekke at ekkes-corner.org>>
>> Cc: interest at qt-project.org <mailto:interest at qt-project.org>
>> 
>> 
>> No one?
>> 
>>> Am 09.10.2018 um 14:54 schrieb Roman Wüger <roman.wueger at gmx.at <mailto:roman.wueger at gmx.at>>:
>>> 
>>> 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 
>>> 
>>>> Am 09.10.2018 um 14:50 schrieb Roman Wüger <roman.wueger at gmx.at <mailto:roman.wueger at gmx.at>>:
>>>> 
>>>> 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
>>>> 
>>>>> Am 08.10.2018 um 13:30 schrieb ekke <ekke at ekkes-corner.org <mailto:ekke at ekkes-corner.org>>:
>>>>> 
>>>>> have you tried 5.11.2, 5.12 Beta or 5.10.1 ?
>>>>> 
>>>>>> Am 08.10.18 um 12:35 schrieb Roman Wüger:
>>>>>> 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
>>>>>> Interest at qt-project.org <mailto:Interest at qt-project.org>
>>>>>> http://lists.qt-project.org/mailman/listinfo/interest
>>>>>> 
>>>>> 
>>>>> _______________________________________________
>>>>> Interest mailing list
>>>>> Interest at qt-project.org <mailto:Interest at qt-project.org>
>>>>> http://lists.qt-project.org/mailman/listinfo/interest
>>>> 
>>>> _______________________________________________
>>>> Interest mailing list
>>>> Interest at qt-project.org <mailto:Interest at qt-project.org>
>>>> http://lists.qt-project.org/mailman/listinfo/interest
>>> 
>>> _______________________________________________
>>> Interest mailing list
>>> Interest at qt-project.org <mailto:Interest at qt-project.org>
>>> http://lists.qt-project.org/mailman/listinfo/interest
>> 
>> 
>> 
>> 
>> 
>> From: Roman Wüger <roman.wueger at gmx.at <mailto:roman.wueger at gmx.at>>
>> Subject: [Interest] Problem with font size on Android and High DPI
>> Date: November 14, 2018 at 12:11:13 PM AST
>> To: Qt Project MailingList <interest at qt-project.org <mailto:interest at qt-project.org>>
>> 
>> 
>> 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
>> 
>> 
>> 
>> 
>> From: ekke <ekke at ekkes-corner.org <mailto:ekke at ekkes-corner.org>>
>> Subject: Re: [Interest] Problem with font size on Android and High DPI
>> Date: November 14, 2018 at 12:15:09 PM AST
>> To: interest at qt-project.org <mailto:interest at qt-project.org>
>> 
>> 
>> Am 14.11.18 um 17:11 schrieb Roman Wüger:
>>> 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
>>> Interest at qt-project.org <mailto:Interest at qt-project.org>
>>> http://lists.qt-project.org/mailman/listinfo/interest
>>> 
>> what kind of application ?
>> 
>> QtQuickControls2 ?
>> 
>> ekke
>> 
>> 
>> 
>> 
>> 
>> From: Roman Wüger <roman.wueger at gmx.at <mailto:roman.wueger at gmx.at>>
>> Subject: Re: [Interest] Problem with font size on Android and High DPI
>> Date: November 14, 2018 at 12:29:36 PM AST
>> To: ekke <ekke at ekkes-corner.org <mailto:ekke at ekkes-corner.org>>
>> Cc: interest at qt-project.org <mailto:interest at qt-project.org>
>> 
>> 
>> 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
>> 
>>> Am 14.11.2018 um 17:15 schrieb ekke <ekke at ekkes-corner.org <mailto:ekke at ekkes-corner.org>>:
>>> 
>>>> Am 14.11.18 um 17:11 schrieb Roman Wüger:
>>>> 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
>>>> Interest at qt-project.org <mailto:Interest at qt-project.org>
>>>> http://lists.qt-project.org/mailman/listinfo/interest
>>>> 
>>> what kind of application ?
>>> 
>>> QtQuickControls2 ?
>>> 
>>> ekke
>>> 
>>> _______________________________________________
>>> Interest mailing list
>>> Interest at qt-project.org <mailto:Interest at qt-project.org>
>>> http://lists.qt-project.org/mailman/listinfo/interest
>> 
>> 
>> 
>> 
>> 
>> From: Thiago Macieira <thiago.macieira at intel.com <mailto:thiago.macieira at intel.com>>
>> Subject: Re: [Interest] QDir::entry(Info)List on macos
>> Date: November 14, 2018 at 12:34:02 PM AST
>> To: <interest at qt-project.org <mailto:interest at qt-project.org>>
>> 
>> 
>> On Wednesday, 14 November 2018 01:34:17 PST Manner Róbert wrote:
>>> 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
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> From: Jérôme Godbout <godboutj at amotus.ca <mailto:godboutj at amotus.ca>>
>> Subject: Re: [Interest] Problem with font size on Android and High DPI
>> Date: November 14, 2018 at 1:17:27 PM AST
>> To: Roman Wüger <roman.wueger at gmx.at <mailto:roman.wueger at gmx.at>>, ekke <ekke at ekkes-corner.org <mailto:ekke at ekkes-corner.org>>
>> Cc: "interest at qt-project.org <mailto:interest at qt-project.org>" <interest at qt-project.org <mailto:interest at qt-project.org>>
>> 
>> 
>> Take care the pixel density is way different on a mobile device form a normal desktop window. You might need to adjust your sizing for many thing. I do the following, I develop on a particular device with REFERENCE SIZE:
>> 
>> // 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-----
>> From: Interest <interest-bounces+godboutj=amotus.ca at qt-project.org <mailto:interest-bounces+godboutj=amotus.ca at qt-project.org>> On Behalf Of Roman Wüger
>> Sent: November 14, 2018 11:30 AM
>> To: ekke <ekke at ekkes-corner.org <mailto:ekke at ekkes-corner.org>>
>> Cc: interest at qt-project.org <mailto:interest at qt-project.org>
>> 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
>> 
>>> Am 14.11.2018 um 17:15 schrieb ekke <ekke at ekkes-corner.org <mailto:ekke at ekkes-corner.org>>:
>>> 
>>>> Am 14.11.18 um 17:11 schrieb Roman Wüger:
>>>> 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
>>>> Interest at qt-project.org <mailto:Interest at qt-project.org>
>>>> http://lists.qt-project.org/mailman/listinfo/interest
>>>> 
>>> what kind of application ?
>>> 
>>> QtQuickControls2 ?
>>> 
>>> ekke
>>> 
>>> _______________________________________________
>>> Interest mailing list
>>> Interest at qt-project.org <mailto:Interest at qt-project.org>
>>> http://lists.qt-project.org/mailman/listinfo/interest
>> 
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org <mailto:Interest at qt-project.org>
>> http://lists.qt-project.org/mailman/listinfo/interest
>> 
>> 
>> 
>> From: Roman Wüger <roman.wueger at gmx.at>
>> Subject: Re: [Interest] Problem with font size on Android and High DPI
>> Date: November 14, 2018 at 2:32:06 PM AST
>> To: Jérôme Godbout <godboutj at amotus.ca>
>> Cc: ekke <ekke at ekkes-corner.org>, "interest at qt-project.org" <interest at qt-project.org>
>> 
>> 
>> And then I need to go over all widgets and multiply the font scale with current font size?
>> 
>> Regards 
>> 
>>> Am 14.11.2018 um 18:17 schrieb Jérôme Godbout <godboutj at amotus.ca>:
>>> 
>>> Take care the pixel density is way different on a mobile device form a normal desktop window. You might need to adjust your sizing for many thing. I do the following, I develop on a particular device with REFERENCE SIZE:
>>> 
>>> // 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-----
>>> From: Interest <interest-bounces+godboutj=amotus.ca at qt-project.org> On Behalf Of Roman Wüger
>>> Sent: November 14, 2018 11:30 AM
>>> To: ekke <ekke at ekkes-corner.org>
>>> Cc: interest at qt-project.org
>>> 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
>>> 
>>>>> Am 14.11.2018 um 17:15 schrieb ekke <ekke at ekkes-corner.org>:
>>>>> 
>>>>> Am 14.11.18 um 17:11 schrieb Roman Wüger:
>>>>> 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
>>>>> Interest at qt-project.org
>>>>> http://lists.qt-project.org/mailman/listinfo/interest
>>>>> 
>>>> what kind of application ?
>>>> 
>>>> QtQuickControls2 ?
>>>> 
>>>> ekke
>>>> 
>>>> _______________________________________________
>>>> Interest mailing list
>>>> Interest at qt-project.org
>>>> http://lists.qt-project.org/mailman/listinfo/interest
>>> 
>>> _______________________________________________
>>> Interest mailing list
>>> Interest at qt-project.org
>>> http://lists.qt-project.org/mailman/listinfo/interest
>> 
>> 
>> 
>> 
>> 
>> From: Manner Róbert <rmanni at gmail.com>
>> Subject: Re: [Interest] QDir::entry(Info)List on macos
>> Date: November 15, 2018 at 3:54:38 AM AST
>> To: interest at qt-project.org
>> 
>> 
>> On 11/14/18 5:34 PM, Thiago Macieira wrote:
>>> On Wednesday, 14 November 2018 01:34:17 PST Manner Róbert wrote:
>>>> 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 is utf8:
>> 
>>> 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"
>> 
>> The modified source code:
>> 
>>> 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
>> 
>> 
>> 
>> 
>> 
>> From: "Olivier B." <perso.olivier.barthelemy at gmail.com>
>> Subject: Re: [Interest] QDir::entry(Info)List on macos
>> Date: November 15, 2018 at 4:49:08 AM AST
>> To: rmanni at gmail.com
>> Cc: interest at qt-project.org
>> 
>> 
>> 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?
>> Le jeu. 15 nov. 2018 à 08:55, Manner Róbert <rmanni at gmail.com> a écrit :
>>> 
>>> On 11/14/18 5:34 PM, Thiago Macieira wrote:
>>>> On Wednesday, 14 November 2018 01:34:17 PST Manner Róbert wrote:
>>>>> 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 is utf8:
>>> 
>>>> 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"
>>> 
>>> The modified source code:
>>> 
>>>> 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
>>> Interest at qt-project.org
>>> http://lists.qt-project.org/mailman/listinfo/interest
>> 
>> 
>> 
>> 
>> From: Manner Róbert <rmanni at gmail.com>
>> Subject: Re: [Interest] QDir::entry(Info)List on macos
>> Date: November 15, 2018 at 9:54:22 AM AST
>> To: "Olivier B." <perso.olivier.barthelemy at gmail.com>
>> Cc: interest at qt-project.org
>> 
>> 
>> Hi,
>> 
>> ((
>> My local encoding is utf-8, so the source file seems to be the same as well:
>>> file main.cpp
>> main.cpp: c program text, UTF-8 Unicode text
>> ))
>> 
>> I think I have found the bug which causes this:
>> https://bugreports.qt.io/browse/QTBUG-70732
>> 
>> I am currently working on a workaround, I am now able to list the files
>> now using <dirent.h>:
>> 
>>         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" (==
>> "normalization format C") UTF-8 strings. Eg.:
>> 
>>   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
>> 
>> 
>> On 11/15/18 9:49 AM, Olivier B. wrote:
>>> 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?
>>> Le jeu. 15 nov. 2018 à 08:55, Manner Róbert <rmanni at gmail.com> a écrit :
>>>> On 11/14/18 5:34 PM, Thiago Macieira wrote:
>>>>> On Wednesday, 14 November 2018 01:34:17 PST Manner Róbert wrote:
>>>>>> 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 is utf8:
>>>> 
>>>>> 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"
>>>> 
>>>> The modified source code:
>>>> 
>>>>> 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
>>>> Interest at qt-project.org
>>>> http://lists.qt-project.org/mailman/listinfo/interest
>> 
>> 
>> 
>> 
>> 
>> 
>> From: Jérôme Godbout <godboutj at amotus.ca>
>> Subject: Re: [Interest] Problem with font size on Android and High DPI
>> Date: November 15, 2018 at 10:42:20 AM AST
>> To: Roman Wüger <roman.wueger at gmx.at>
>> Cc: ekke <ekke at ekkes-corner.org>, "interest at qt-project.org" <interest at qt-project.org>
>> 
>> 
>> 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-----
>> From: Roman Wüger <roman.wueger at gmx.at> 
>> Sent: November 14, 2018 1:32 PM
>> To: Jérôme Godbout <godboutj at amotus.ca>
>> Cc: ekke <ekke at ekkes-corner.org>; interest at qt-project.org
>> 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 
>> 
>>> Am 14.11.2018 um 18:17 schrieb Jérôme Godbout <godboutj at amotus.ca>:
>>> 
>>> Take care the pixel density is way different on a mobile device form a normal desktop window. You might need to adjust your sizing for many thing. I do the following, I develop on a particular device with REFERENCE SIZE:
>>> 
>>> // 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-----
>>> From: Interest <interest-bounces+godboutj=amotus.ca at qt-project.org> On Behalf Of Roman Wüger
>>> Sent: November 14, 2018 11:30 AM
>>> To: ekke <ekke at ekkes-corner.org>
>>> Cc: interest at qt-project.org
>>> 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
>>> 
>>>>> Am 14.11.2018 um 17:15 schrieb ekke <ekke at ekkes-corner.org>:
>>>>> 
>>>>> Am 14.11.18 um 17:11 schrieb Roman Wüger:
>>>>> 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
>>>>> Interest at qt-project.org
>>>>> http://lists.qt-project.org/mailman/listinfo/interest
>>>>> 
>>>> what kind of application ?
>>>> 
>>>> QtQuickControls2 ?
>>>> 
>>>> ekke
>>>> 
>>>> _______________________________________________
>>>> Interest mailing list
>>>> Interest at qt-project.org
>>>> http://lists.qt-project.org/mailman/listinfo/interest
>>> 
>>> _______________________________________________
>>> Interest mailing list
>>> Interest at qt-project.org
>>> http://lists.qt-project.org/mailman/listinfo/interest
>> 
>> 
>> 
>> 
>> From: Nguyen Ngoc Thach Chau <chaupad at gmail.com>
>> Subject: Re: [Interest] Problem with font size on Android and High DPI
>> Date: November 15, 2018 at 11:04:41 AM AST
>> To: godboutj at amotus.ca
>> Cc: roman.wueger at gmx.at, interest at qt-project.org
>> 
>> 
>>         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".
>> 
>> 
>> On Thu, Nov 15, 2018 at 9:42 PM Jérôme Godbout <godboutj at amotus.ca <mailto:godboutj at amotus.ca>> wrote:
>> 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-----
>> From: Roman Wüger <roman.wueger at gmx.at <mailto:roman.wueger at gmx.at>> 
>> Sent: November 14, 2018 1:32 PM
>> To: Jérôme Godbout <godboutj at amotus.ca <mailto:godboutj at amotus.ca>>
>> Cc: ekke <ekke at ekkes-corner.org <mailto:ekke at ekkes-corner.org>>; interest at qt-project.org <mailto:interest at qt-project.org>
>> 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 
>> 
>> > Am 14.11.2018 um 18:17 schrieb Jérôme Godbout <godboutj at amotus.ca <mailto:godboutj at amotus.ca>>:
>> > 
>> > Take care the pixel density is way different on a mobile device form a normal desktop window. You might need to adjust your sizing for many thing. I do the following, I develop on a particular device with REFERENCE SIZE:
>> > 
>> > // 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-----
>> > From: Interest <interest-bounces+godboutj=amotus.ca at qt-project.org <mailto:amotus.ca at qt-project.org>> On Behalf Of Roman Wüger
>> > Sent: November 14, 2018 11:30 AM
>> > To: ekke <ekke at ekkes-corner.org <mailto:ekke at ekkes-corner.org>>
>> > Cc: interest at qt-project.org <mailto:interest at qt-project.org>
>> > 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
>> > 
>> >>> Am 14.11.2018 um 17:15 schrieb ekke <ekke at ekkes-corner.org <mailto:ekke at ekkes-corner.org>>:
>> >>> 
>> >>> Am 14.11.18 um 17:11 schrieb Roman Wüger:
>> >>> 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
>> >>> Interest at qt-project.org <mailto:Interest at qt-project.org>
>> >>> 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
>> >> Interest at qt-project.org <mailto:Interest at qt-project.org>
>> >> http://lists.qt-project.org/mailman/listinfo/interest <http://lists.qt-project.org/mailman/listinfo/interest>
>> > 
>> > _______________________________________________
>> > Interest mailing list
>> > Interest at qt-project.org <mailto:Interest at qt-project.org>
>> > http://lists.qt-project.org/mailman/listinfo/interest <http://lists.qt-project.org/mailman/listinfo/interest>
>> 
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org <mailto:Interest at qt-project.org>
>> http://lists.qt-project.org/mailman/listinfo/interest <http://lists.qt-project.org/mailman/listinfo/interest>
>> 
>> 
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
> 
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20181115/7ef3fdc3/attachment.html>


More information about the Interest mailing list