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. Append data on a file using QSetting
Forum Updated to NodeBB v4.3 + New Features

Append data on a file using QSetting

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 614 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.
  • L Offline
    L Offline
    LovelyGrace
    wrote on last edited by
    #1

    Is it possible to keep the old data and append the new data everytime the program runs on QSetting;

    QString file = QApplication::applicationDirPath() + "/sample.ini";
    qDebug() << QApplication::applicationDirPath() << endl;
    QSettings settings(file, QSettings::IniFormat);
    settings.beginGroup("Sample");
    settings.setValue("Username", "John");
    settings.setValue("Password", "12345678");
    settings.endGroup();

    What happens here is it only keeps new data. I tried adding a count on begingroup function but it error.

    JonBJ J.HilkJ 2 Replies Last reply
    0
    • L LovelyGrace

      Is it possible to keep the old data and append the new data everytime the program runs on QSetting;

      QString file = QApplication::applicationDirPath() + "/sample.ini";
      qDebug() << QApplication::applicationDirPath() << endl;
      QSettings settings(file, QSettings::IniFormat);
      settings.beginGroup("Sample");
      settings.setValue("Username", "John");
      settings.setValue("Password", "12345678");
      settings.endGroup();

      What happens here is it only keeps new data. I tried adding a count on begingroup function but it error.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @LovelyGrace
      Don't understand what you mean. Your code reads in the existing settings. You create/overwrite Sample/Username & Sample/Password. If you mean to instead create Sample2/Username & Sample2/Password etc. then .beginGroup("Sample2"); would do that.

      Perhaps you should show what your .ini file looks like before & after your code, what you would like it to end up as, and what you tried?

      1 Reply Last reply
      4
      • L LovelyGrace

        Is it possible to keep the old data and append the new data everytime the program runs on QSetting;

        QString file = QApplication::applicationDirPath() + "/sample.ini";
        qDebug() << QApplication::applicationDirPath() << endl;
        QSettings settings(file, QSettings::IniFormat);
        settings.beginGroup("Sample");
        settings.setValue("Username", "John");
        settings.setValue("Password", "12345678");
        settings.endGroup();

        What happens here is it only keeps new data. I tried adding a count on begingroup function but it error.

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

        @LovelyGrace
        I would suggest looking into the documentation of QSettings and the section about arrays.

        https://doc.qt.io/qt-5/qsettings.html#beginReadArray

        Seems like that should cover what you want to do.


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        3

        • Login

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