Results 1 to 6 of 6

Thread: QSettings , read only avaiable?

  1. #1
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QSettings , read only avaiable?

    I try to find the path from GPL Ghostscript ..
    I find the path ... and is installed 8.60.
    Now how i can make QSettings read only...
    to not make 39 new Regedit empty path?


    Qt Code:
    1. /* find gpl GhostScript path or exe */
    2. QString PS_utils::getGSDefaultExeName()
    3. {
    4. QString gsName;
    5. #if defined Q_WS_WIN
    6. QFileInfo Pinfo;
    7. // Try to locate GhostScript thanks to the qsetting
    8. gsName = "gswin32c.exe";
    9. for(int i=0;i<99;i++) {
    10. /* loop all avaiable version on 8+ */
    11. QSettings gs_sett("HKEY_LOCAL_MACHINE\\Software\\GPL Ghostscript\\8."+QString("%1").arg(100 - i),QSettings::NativeFormat);
    12. if (gs_sett.allKeys().size() > 2) {
    13. if (gs_sett.value("GS_DLL").toString().size() > 4) {
    14. Pinfo.setFile(gs_sett.value("GS_DLL").toString());
    15. return gsName.prepend(Pinfo.absolutePath()+"/");
    16. }
    17. }
    18. }
    19. for(int e=0;e<99;e++) {
    20. /* loop all avaiable version on 7+ */
    21. QSettings gs_sett7("HKEY_LOCAL_MACHINE\\Software\\GPL Ghostscript\\7."+QString("%1").arg(100 - e),QSettings::NativeFormat);
    22. if (gs_sett7.allKeys().size() > 2) {
    23. if (gs_sett7.value("GS_DLL").toString().size() > 4) {
    24. Pinfo.setFile(gs_sett7.value("GS_DLL").toString());
    25. return gsName.prepend(Pinfo.absolutePath()+"/");
    26. }
    27. }
    28. }
    29. /* win not having GPL Ghostscript ! */
    30. gsName = "gs";
    31. #else
    32. gsName = "gs";
    33. #endif
    34. return gsName;
    35. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QSettings , read only avaiable?

    You might want to construct only one QSettings object instead of constructing hundreds of them in those loops. Start iterating from "HKEY_LOCAL_MACHINE\\Software" and go deeper in the hierarchy only if childGroups() contains "GPL Ghostscript" etc.
    J-P Nurmi

  3. #3
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QSettings , read only avaiable?

    Quote Originally Posted by jpn View Post
    You might want to construct only one QSettings object instead of constructing hundreds of them in those loops. Start iterating from "HKEY_LOCAL_MACHINE\\Software" and go deeper in the hierarchy only if childGroups() contains "GPL Ghostscript" etc.

    This work on GPL Ghostscript ..
    if (AFPL Ghostscript) i suppose can find...

    Tanks for idea...


    Qt Code:
    1. /* find gpl GhostScript path or exe */
    2. QString PS_utils::getGSDefaultExeName()
    3. {
    4. QString gsName;
    5. QString gVersion;
    6. #if defined Q_WS_WIN
    7. QFileInfo Pinfo;
    8. // Try to locate GhostScript thanks to the qsetting
    9. gsName = "gswin32c.exe";
    10. QSettings softs("HKEY_LOCAL_MACHINE\\Software",QSettings::NativeFormat);
    11. QStringList allsoftware = softs.childGroups();
    12. for (int i = 0; i < allsoftware.size(); ++i) {
    13. const QString RealName = allsoftware.at(i); /* realpath */
    14. if (RealName.contains("Ghostscript")) {
    15. qDebug() << "### soft " << RealName;
    16. for(int e=1;e<99;e++) {
    17. /* check version 8 ++ 99 down */
    18. gVersion = QString("8.%1").arg(100 - e);
    19. if (softs.value(RealName+"/"+gVersion+"/GS_DLL").toString().size() > 6 ) {
    20. Pinfo.setFile(softs.value(RealName+"/"+gVersion+"/GS_DLL").toString());
    21. return gsName.prepend(Pinfo.absolutePath()+"/");
    22. }
    23. /* check version 7 ++ 99 down */
    24. gVersion = QString("7.%1").arg(100 - e);
    25. if (softs.value(RealName+"/"+gVersion+"/GS_DLL").toString().size() > 6 ) {
    26. Pinfo.setFile(softs.value(RealName+"/"+gVersion+"/GS_DLL").toString());
    27. return gsName.prepend(Pinfo.absolutePath()+"/");
    28. }
    29. }
    30. }
    31. }
    32.  
    33. /* win not having GPL Ghostscript ! */
    34. gsName = "rundll32.exe url.dll,FileProtocolHandler http://pages.cs.wisc.edu/~ghost/";
    35. #else
    36. gsName = "gs";
    37. #endif
    38. return gsName;
    39. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QSettings , read only avaiable?

    Those loops still bother me so here's an improvement idea:
    Qt Code:
    1. QStringList allsoftware = softs.childGroups();
    2. // pick matching strings
    3. QStringList gs = allsoftware.filter(QRegExp("Ghostscript \\d+\\.\\d+"));
    4. // sort by version
    5. qSort(gs.begin(), gs.end(), gsVersionGreaterThan);
    6. // now the first item of gs is "Ghostscript M.N" with latest version (unless gs is empty, of course)
    To copy to clipboard, switch view to plain text mode 
    The compare function would look more or less something like this:
    Qt Code:
    1. bool gsVersionGreaterThan(const QString& s1, const QString& s2)
    2. {
    3. QRegExp regExp1("Ghostscript (\\d+)\\.(\\d+)");
    4. QRegExp regExp2("Ghostscript (\\d+)\\.(\\d+)");
    5. int pos1 = regExp1.indexIn(s1);
    6. int pos2 = regExp2.indexIn(s2);
    7. if (pos1 > -1 && pos2 > -1)
    8. {
    9. int maj1 = regExp1.cap(1).toInt();
    10. int maj2 = regExp2.cap(1).toInt();
    11. int min1 = regExp1.cap(2).toInt();
    12. int min2 = regExp2.cap(2).toInt();
    13. return maj1 > maj2 || (maj1 == maj2 && min1 > min2);
    14. }
    15. return false;
    16. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  5. #5
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QSettings , read only avaiable?

    Quote Originally Posted by jpn View Post
    Those loops still bother me so here's an improvement idea:
    Qt Code:
    1. QStringList allsoftware = softs.childGroups();
    2. // pick matching strings
    3. QStringList gs = allsoftware.filter(QRegExp("Ghostscript \\d+\\.\\d+"));
    4. // sort by version
    5. qSort(gs.begin(), gs.end(), gsVersionGreaterThan);
    6. // now the first item of gs is "Ghostscript M.N" with latest version (unless gs is empty, of course)
    To copy to clipboard, switch view to plain text mode 
    You forget the separator //\\

    version xx is other childGroups().

    avaiable is:
    GPL Ghostscript/8.60/
    GPL Ghostscript/8.53/
    GPL Ghostscript/7.07/
    AFPL Ghostscript/8.54/
    AFPL Ghostscript/8.50/

    GPL Ghostscript / * version 10 time
    AFPL Ghostscript / * version 12 time

    QRegExp("Ghostscript") find to AFPL Ghostscript and return a small list..


    Qt Code:
    1. QStringList gsonly = allsoftware.filter(QRegExp("Ghostscript"));
    2. qDebug() << "### gsonly " << gsonly;
    3. /* return ### gsonly ("GPL Ghostscript") */
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. QStringList gsonly = allsoftware.filter(QRegExp("Ghostscript \\d+\\.\\d+"));
    2. qDebug() << "### gsonly " << gsonly;
    3. /* return ### gsonly ("") not found */
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QSettings , read only avaiable?

    Well, like I said, it was an improvement idea. I didn't even mean to give a 100% ready solution.

    But alright, this changes the situation a bit. It might be easiest to check whether such application exists, go into the child group and pick version numbers:
    Qt Code:
    1. QStringList allsoftware = settings.childGroups();
    2. if (allsoftware.contains("GPL Ghostscript"))
    3. {
    4. settings.beginGroup("GPL Ghostscript");
    5. QStringList versions = settings.childGroups();
    6. qSort(versions.begin(), versions.end(), versionGreaterThan);
    7. settings.endGroup();
    8. ...
    9. }
    To copy to clipboard, switch view to plain text mode 
    This also simplifies the compare function a bit.
    J-P Nurmi

  7. The following user says thank you to jpn for this useful post:

    patrik08 (18th November 2007)

Similar Threads

  1. How to read CD with read?
    By vishal.chauhan in forum Qt Programming
    Replies: 6
    Last Post: 29th June 2007, 08:20
  2. Using QSettings to read pre-made INI file..
    By ShaChris23 in forum Newbie
    Replies: 1
    Last Post: 3rd May 2007, 05:36
  3. QIODevice read()
    By ShaChris23 in forum Newbie
    Replies: 1
    Last Post: 3rd May 2007, 00:29

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.