Results 1 to 11 of 11

Thread: Qt4: How to get the Common Application Data folder path?

  1. #1
    Join Date
    Oct 2006
    Location
    Bangalore
    Posts
    32
    Qt products
    Qt4
    Platforms
    Windows

    Default Qt4: How to get the Common Application Data folder path?

    Hi,

    I am porting MFC code to Qt4.

    There is a method in MFC namely SHGetFolderPath which gives the path of the folder given the CSIDL value.

    For the current code I am porting, the CSDIL value is "CSIDL_COMMON_APPDATA" Which yeilds a typical path "C:\Documents and Settings\All Users\Application Data".

    In Qt, the nearest thing I know is QDesktopServices::StandardLocation. But for the location/path that CSIDL_COMMON_APPDATA returns in MFC, I am not sure how to get the same location in Qt.

    Please help.

    /Ankitha.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt4: How to get the Common Application Data folder path?

    You can use the MFC code in Qt too , cant you

  3. #3
    Join Date
    Oct 2006
    Location
    Bangalore
    Posts
    32
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qt4: How to get the Common Application Data folder path?

    Oh no.
    The project is multiplatform
    And the purpose it is to port all the MFC to code to Qt.

  4. #4
    Join Date
    Jan 2007
    Posts
    177
    Thanks
    8
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt4: How to get the Common Application Data folder path?

    i think you have to do use QDir::homePath() or QDir::rootPath().
    Eg:
    QString appDir = QDir::homePath() + "/Application Data/";
    QString appDir = QDir::rootPath() + /"Documents and Settings/All Users/Application Data/";

  5. #5
    Join Date
    Oct 2006
    Location
    Bangalore
    Posts
    32
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qt4: How to get the Common Application Data folder path?

    Quote Originally Posted by kernel_panic View Post
    QString appDir = QDir::homePath() + "/Application Data/";
    QString appDir = QDir::rootPath() + /"Documents and Settings/All Users/Application Data/";
    In the above code, if the platforms are different, is it possible that the common Application Data path might differ? I mean to ask, will there be "Documents and Settings/All Users/Application Data/" under root path for that platform , be it windows, Unix or Mac? I am sorry if the question is silly, I have been working on only windows since very long time.

    /Ankitha

  6. #6
    Join Date
    Jan 2007
    Posts
    177
    Thanks
    8
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt4: How to get the Common Application Data folder path?

    use Q_WS_WIN Q_WS_X11 and Q_WS_MAC for getting the current path:
    #ifdef Q_WS_WIN
    QString appDir = QDir::homePath() + "/Application Data/";
    #elif defined(Q_WS_X11)
    QString appDir = QDir::homePath() + "/.config/yourapp/";
    #endif

  7. #7
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt4: How to get the Common Application Data folder path?

    I mean to ask, will there be "Documents and Settings/All Users/Application Data/" under root path for that platform , be it windows, Unix or Mac?
    NO.

    Go as kenel_panic has suggested.

  8. #8
    Join Date
    Oct 2006
    Location
    Bangalore
    Posts
    32
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qt4: How to get the Common Application Data folder path?

    Neat
    Thanks a lot

  9. #9
    Join Date
    Jan 2006
    Posts
    369
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt4: How to get the Common Application Data folder path?

    be warned that those directories might have different names, depending on the windows locale.

    Check MSDN for the correct function to use. On linux, just put stuff on the user's home directory, no real standard here.

  10. #10
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt4: How to get the Common Application Data folder path?

    On Windows all this information You can read from system register from key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Curr entVersion\Explorer\Shell Folders. In example to read location of All User Desktop :
    Qt Code:
    1. QSettings register("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", QSettings::NativeFormat);
    2. QString allUserDesktop( register.value("Common Desktop").toString());
    To copy to clipboard, switch view to plain text mode 
    Last edited by Lesiok; 21st October 2008 at 07:37.

  11. The following user says thank you to Lesiok for this useful post:

    minimoog (30th December 2008)

  12. #11
    Join Date
    Oct 2006
    Location
    Bangalore
    Posts
    32
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qt4: How to get the Common Application Data folder path?

    This was very useful.
    Thank you so much.

Similar Threads

  1. Path to the previous folder
    By Zergi in forum Newbie
    Replies: 2
    Last Post: 15th July 2008, 18:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.