[Interest] QSettings possible bug on Windows

Scott Aron Bloom scott.bloom at onshorecs.com
Tue Oct 1 06:52:13 CEST 2013


I had to extend desktop services out of the UI library...


From: Alex Malyushytskyy [mailto:alexmalvtk at gmail.com]
Sent: Monday, September 30, 2013 9:30 PM
To: Scott Aron Bloom
Cc: interest at qt-project.org
Subject: Re: [Interest] QSettings possible bug on Windows

Thanks Scott for advices,
-  10 times checked that there was no typo

qdesktopservices do not provide path to common application data folder, only to user specific.
Reason I guess that there is no such concept on unix derived systems.
I finally did write an extension to it which on Windows returns value I am looking for
basically it is call to SHGetSpecialFolderPath with CSIDL_COMMON_APPDATA parameter.and on Linux returns results obtained with QDesktopServices::DataLocation

This is supposed to be a right way to dt it anyway (besides extending qdesktopservices which would be probably even better) ,
but it does not explain problem I see with QSettings
Regards,

Alex


On Mon, Sep 30, 2013 at 8:17 PM, Scott Aron Bloom <scott.bloom at onshorecs.com<mailto:scott.bloom at onshorecs.com>> wrote:
Two things..


1)      Try doing a foreach( const QString & child, reg.childKeys() ) and see, maybe there is a typo you are missing

2)      Take a look at the Qt source code for qdesktopservices_win.cpp  It uses SHGetSpecialFolder to find the directories you are looking for.
Scott

From: interest-bounces+scott.bloom=onshorecs.com at qt-project.org<mailto:onshorecs.com at qt-project.org> [mailto:interest-bounces+scott.bloom<mailto:interest-bounces%2Bscott.bloom>=onshorecs.com at qt-project.org<mailto:onshorecs.com at qt-project.org>] On Behalf Of Alex Malyushytskyy
Sent: Monday, September 30, 2013 7:02 PM
To: interest at qt-project.org<mailto:interest at qt-project.org>
Subject: Re: [Interest] QSettings possible bug on Windows

Just want to add that key is found,

qDebug() << "child keys = " <<  reg.childKeys();
result in

child keys =  ("Common Administrative Tools", "Common AppData", "Common Desktop", "Common Documents", "Common Programs", "Common Start Menu", "Common Startup", "Common Templates", "CommonMusic", "CommonPictures", "CommonVideo", "OEM Links", "Personal")

but value returned is empty string - different from visible in regedit
Alex

On Mon, Sep 30, 2013 at 6:24 PM, Alex Malyushytskyy <alexmalvtk at gmail.com<mailto:alexmalvtk at gmail.com>> wrote:
I found a problem with QSettings when trying to read from registry.
I am using  Qt 4.7.3 so I would appreciate if anybody can check with Qt 5 at least.
Problem:
QSettings fails to return specific key value (Common AppData) when read other keys at the same level just fine.
Key exists and verified with regedit.
Test case is below:

#include <QApplication>
#include <QSettings>
#include <QDebug>

void ddd2();

int main(int argc, char *argv[])
{
// execute test and return
    QApplication a(argc, argv);
    ddd2();

    return 0;
}

void ddd2()
{
    QSettings reg("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
        QSettings::NativeFormat);
    QString key;
    QString val;

    key = QString("Common AppData");
    val = QString ( reg.value(key).toString());
    qDebug() << "key: " << key << " value: " << val;

    key = QString("Common Desktop");
    val = QString ( reg.value(key).toString());
    qDebug() << "key: " << key << " value: " << val;

    key = QString("Common Documents");
    val = QString ( reg.value(key).toString());
    qDebug() << "key: " << key << " value: " << val;
}
Output:

key:  "Common AppData"  value:  ""
key:  "Common Desktop"  value:  "C:\Users\Public\Desktop"
key:  "Common Documents"  value:  "C:\Users\Public\Documents"
Expected
 * WinXP: "c:\Documents and Settings\All Users\Application Data"
 * WinV/7/8: "c:\ProgramData"
Regards,
   Alex


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


More information about the Interest mailing list