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. Problem with QSettings
Forum Updated to NodeBB v4.3 + New Features

Problem with QSettings

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 358 Views 1 Watching
  • 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.
  • A Offline
    A Offline
    amy.cpp
    wrote on 17 Apr 2020, 17:17 last edited by
    #1

    Hi guys!
    Can you explain me why this code doesn't work?
    It looks so easy.

    QSettings settings;
    settings.setValue("key", 123);
    
    settings.sync();
    
    qInfo() << settings.value("key");
    
    return a.exec();
    

    Thank you

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bonnie
      wrote on 17 Apr 2020, 17:39 last edited by Bonnie
      #2

      Is that your full code about QSettings?
      Then according to the doc:

      QSettings::QSettings(QObject *parent = nullptr)

      Constructs a QSettings object for accessing settings of the application and organization set previously with a call to QCoreApplication::setOrganizationName(), QCoreApplication::setOrganizationDomain(), and QCoreApplication::setApplicationName().
      The scope is QSettings::UserScope and the format is defaultFormat() (QSettings::NativeFormat by default). Use setDefaultFormat() before calling this constructor to change the default format used by this constructor.
      The code

      QSettings settings("Moose Soft", "Facturo-Pro");

      is equivalent to

      QCoreApplication::setOrganizationName("Moose Soft");
      QCoreApplication::setApplicationName("Facturo-Pro");
      QSettings settings;

      If QCoreApplication::setOrganizationName() and QCoreApplication::setApplicationName() has not been previously called, the QSettings object will not be able to read or write any settings, and status() will return AccessError.

      You could try using a filename when creating QSettings:
      QSettings settings("settings.ini", QSettings::IniFormat);

      A 1 Reply Last reply 17 Apr 2020, 17:53
      3
      • B Bonnie
        17 Apr 2020, 17:39

        Is that your full code about QSettings?
        Then according to the doc:

        QSettings::QSettings(QObject *parent = nullptr)

        Constructs a QSettings object for accessing settings of the application and organization set previously with a call to QCoreApplication::setOrganizationName(), QCoreApplication::setOrganizationDomain(), and QCoreApplication::setApplicationName().
        The scope is QSettings::UserScope and the format is defaultFormat() (QSettings::NativeFormat by default). Use setDefaultFormat() before calling this constructor to change the default format used by this constructor.
        The code

        QSettings settings("Moose Soft", "Facturo-Pro");

        is equivalent to

        QCoreApplication::setOrganizationName("Moose Soft");
        QCoreApplication::setApplicationName("Facturo-Pro");
        QSettings settings;

        If QCoreApplication::setOrganizationName() and QCoreApplication::setApplicationName() has not been previously called, the QSettings object will not be able to read or write any settings, and status() will return AccessError.

        You could try using a filename when creating QSettings:
        QSettings settings("settings.ini", QSettings::IniFormat);

        A Offline
        A Offline
        amy.cpp
        wrote on 17 Apr 2020, 17:53 last edited by amy.cpp
        #3

        @Bonnie

        Thank you, the problem is gone :)

        P 1 Reply Last reply 17 Apr 2020, 18:16
        0
        • A amy.cpp
          17 Apr 2020, 17:53

          @Bonnie

          Thank you, the problem is gone :)

          P Offline
          P Offline
          Pablo J. Rogina
          wrote on 17 Apr 2020, 18:16 last edited by
          #4

          @amy-cpp said in Problem with QSettings:

          the problem is gone :)

          so please don't forget to mark your post as solved!

          Upvote the answer(s) that helped you solve the issue
          Use "Topic Tools" button to mark your post as Solved
          Add screenshots via postimage.org
          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          1

          1/4

          17 Apr 2020, 17:17

          • Login

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