Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSettings ini format

QSettings ini format

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 209 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Viktor Khristenko
    wrote on last edited by
    #1

    Hello,

    Going thru QSettings, i have 1 particular question regarding the documentation.

    https://doc.qt.io/qt-6/qsettings.html#fallback-mechanism paragraph, sentence
    Note that INI files lose the distinction between numeric data and the strings used to encode them, so values written as numbers shall be read back as QString. The numeric value can be recovered using QString::toInt(), QString::toDouble() and related functions.

    then QVariant's documentation of toInt (or toDouble for that matter) method contains the following:
    Returns the variant as an int if the variant has userType() QMetaType::Int, QMetaType::Bool, QMetaType::QByteArray, QMetaType::QChar, QMetaType::Double, QMetaType::LongLong, QMetaType::QString, QMetaType::UInt, or QMetaType::ULongLong; otherwise returns 0.

    And doing a small test

    #include <iostream>
    
    #include "QString"
    #include "QSettings"
    
    int main(int argc, char **argv) { 
        std::cout << "hello world!" << std::endl;
    
        QSettings settings{
            QSettings::IniFormat, 
            QSettings::UserScope,
            "Test",
            "Test"
        };
        auto val = settings.value("key1", 10);
        if (!val.isNull()) { 
            std::cout << val.toInt() << std::endl;
        } else { 
            std::cout << "setting key1 = 100!" << std::endl;
            settings.setValue("key1", 100);
        } 
    
        return 0;
    }
    

    running this, i indeed observe getting numeric value back just fine. With what is written about QSettings and IniFormat, i would expect to have to use this:

    QSettings settings{...};
    auto value_as_int = settings.value("key").toString().toInt();
    

    However it seems not to be necessary - my question is if this paragraph about iniFormat should be dropped and it is safe to directly convert to numeric types with QSettings independent of the format used.

    Thanks!

    VK

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      That's a good question, I would rather bring it to the interest mailing list. You'll find there Qt developers/maintainers. This forum is more user oriented.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved