Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [solved] using QSettings
Forum Updated to NodeBB v4.3 + New Features

[solved] using QSettings

Scheduled Pinned Locked Moved Mobile and Embedded
18 Posts 3 Posters 8.2k 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.
  • R Offline
    R Offline
    Robbin
    wrote on last edited by
    #7

    Yes, it IS zero size, that's expected behaviour. You have error in your syntax. From the documentation:
    @
    QSettings settings;
    int size = settings.beginReadArray("logins");
    for (int i = 0; i < size; ++i) {
    @

    and you do:
    @
    settings.beginReadArray("notesList");
    qDebug()<<"text "<<notesList.size();
    for(int i = 0; i < notesList.size() ;++i)
    @

    Get the size in integer variable and use that for the loop.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alfah
      wrote on last edited by
      #8

      ahhh k :)

      mercii :D :D

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alfah
        wrote on last edited by
        #9

        one more question,

        an applications can have as many settings as possible right?

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Robbin
          wrote on last edited by
          #10

          Well you have groups. Just divide your settings in appropriate groups. You can have many settings, and QSettings retrieves the data for you. I don't know about limitation in size.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            alfah
            wrote on last edited by
            #11

            ok,
            somethin else, its said tht qsettings can hold all sort of settings right?
            I have entered stored a date like this
            @
            noteSettings.setValue("setDate",notesList.at(i).setNoteDate);
            @

            reg.setNoteDate is of QDate type
            while reading it back, do we need it to use .toDate()
            like this??
            @
            QDate checkDate=noteSettings.value("setNoteDate").toDate();
            @

            thank you.

            1 Reply Last reply
            0
            • R Offline
              R Offline
              Robbin
              wrote on last edited by
              #12

              yes, there is .toDate() method for QVariant (that's what gets returned by settings.value() method).

              The only trouble you could get with QSettings is if you use GUI types like QColor.
              Read "here":http://doc.qt.nokia.com/stable/qsettings.html for more info

              1 Reply Last reply
              0
              • L Offline
                L Offline
                lgeyer
                wrote on last edited by
                #13

                [quote author="alfah" date="1314021081"]lukas,
                Could you explain to me how both are different and under which situations these are used???[/quote]

                The main differences are

                • sequential access for QDataStream vs random access for QSettings
                • (efficient) binary storage for QDataStream vs text storage for QSettings
                • non-human-readable storage for QDataStream vs human-readable storage for QSettings

                There is no generally accepted rule on usage, but there is a good rule of thumb. QSettings is used to store the state of an application (opened windows, geometry) and settings (credentials, color schemes), whereas the data of an application itself is serialized using QDataStream (or another data storage like QSqlDatabase, QXmlStreamWriter).

                [quote author="alfah" date="1314021081"]The module of mine requires notes to be attached to each date of a custom made calender. So when i click the button, i get another form with a line edit askin the user to input any notes if ...[/quote]

                Have you considered storing the data using the "iCal standard":http://tools.ietf.org/html/rfc5545? This way your data will be interchangeable with many other applications processing calendar data.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  alfah
                  wrote on last edited by
                  #14

                  does QdataStream provide persistent storage?

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    Robbin
                    wrote on last edited by
                    #15

                    Of course, you "stream" the data into a file.

                    1 Reply Last reply
                    0
                    • L Offline
                      L Offline
                      lgeyer
                      wrote on last edited by
                      #16

                      Or any other QIODevice.

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        alfah
                        wrote on last edited by
                        #17

                        will the following lines of code ensure tht Where ever i use the Qsettings, it will open up the same settings files?
                        @

                        QSettings noteSettings("Plackal","Seecycles");
                        noteSettings.setDefaultFormat(QSettings::IniFormat);
                        noteSettings.setPath(QSettings::IniFormat,QSettings::UserScope,QCoreApplication::applicationDirPath());

                        @

                        alfah

                        1 Reply Last reply
                        0
                        • L Offline
                          L Offline
                          lgeyer
                          wrote on last edited by
                          #18

                          Unless your applicationDirPath() doesn't change, yes.

                          Keep in mind that you possibliy have no permission to write to the application directory. This is why you should prefer a user scope directory (like %APPDATA%) over the application directory.

                          1 Reply Last reply
                          0

                          • Login

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