Results 1 to 4 of 4

Thread: INI file gets over written in Qt

  1. #1
    Join Date
    Jun 2013
    Posts
    31
    Thanks
    8
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default INI file gets over written in Qt

    I am creating a config file which stores username, password and role of certain user. I use the following code.

    Qt Code:
    1. void MainWindow::OnAssignButtonClicked()
    2. {
    3. QSettings settings("/root/configFile.ini", QSettings::IniFormat);
    4.  
    5. QString userName = lineEditUsername.text();
    6. QString password = lineEditPassword.text();
    7. QString Role = comboBox.currentText();
    8.  
    9. QList<QString> listUsername;
    10. QList<QString> listPassword;
    11. QList<QString> listRole;
    12.  
    13. QVariantMap userPasswordMapping;
    14. QVariantMap userRoleMapping;
    15.  
    16. listUsername << userName;
    17. listPassWord << Password;
    18. listRole << Role;
    19.  
    20. for(int i = 0; i < listUsername.size() ; i++)
    21. {
    22. QString user = listUsername.at(i);
    23. QString pass = listPassword.at(i);
    24. QString role = listRole.at(i);
    25.  
    26. userPasswordMapping[user] = pass;
    27. userRoleMapping[user] = role;
    28. }
    29.  
    30. // Store the mapping.
    31. settings.setValue("Password", userPasswordMapping);
    32. settings.setValue("Role",userRoleMapping);
    33.  
    34. }
    To copy to clipboard, switch view to plain text mode 
    The first time the value gets written correctly. However if I run the program again the value over writes the old values. Can some one please suggest me a solution here?
    Thank You
    Last edited by SiddhantR; 10th October 2013 at 12:48.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: INI file gets over written in Qt

    You are calling setValue() so the value for that key is stored in the settings. Did you expect it to be different?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2013
    Posts
    31
    Thanks
    8
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: INI file gets over written in Qt

    Ok so what change should I do?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: INI file gets over written in Qt

    Quote Originally Posted by SiddhantR View Post
    Ok so what change should I do?
    I have no idea what you want to achieve.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 1
    Last Post: 7th December 2011, 16:08
  2. Replies: 12
    Last Post: 22nd March 2011, 15:08
  3. Replies: 0
    Last Post: 22nd February 2010, 16:36
  4. PHP extensions written in C++/Qt
    By seim in forum Qt Programming
    Replies: 0
    Last Post: 12th February 2009, 00:40
  5. detecting that a file is currently being written to...
    By momesana in forum Qt Programming
    Replies: 11
    Last Post: 31st October 2007, 13:02

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.