Results 1 to 6 of 6

Thread: Problem with QSettings

  1. #1
    Join Date
    May 2013
    Location
    Russia
    Posts
    4
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Problem with QSettings

    I wrote the application using Qt 4.8 . Now I need rewrite it into Qt 5.0. Using 4.8 QSettings worked right and now it doesn't. I try to save setting to settings.ini and read settings from there, but QSettings doesn't want to write and read.

    My code:
    #include "settingsdialog.h"
    #include "ui_settingsdialog.h"
    #include "QMessageBox"
    #include "QSettings"

    SettingsDialog::SettingsDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::SettingsDialog)
    {
    ui->setupUi(this);
    ui->admin_passwordEdit->setEchoMode(QLineEdit::Password);
    connect(ui->save_settingsButton,SIGNAL(clicked()),this,SLOT(s ave_setting()));
    }

    SettingsDialog::~SettingsDialog()
    {
    delete ui;
    }

    void SettingsDialog::save_setting()
    {
    QSettings setting("setting.ini",QSettings::IniFormat);
    setting->setIniCodec("UTF-8");
    QString host = ui->hostEdit->text();
    QString db_name = ui->db_nameEdit->text();
    QString admin_login=ui->hostEdit->text();
    QString admin_password =ui->hostEdit->text();
    if (!host.isEmpty()) setting->setValue("MySQL/host", host);
    if (!db_name.isEmpty()) setting->setValue("MySQL/db_name", db_name);
    if (!admin_login.isEmpty()) setting->setValue("MySQL/admin_login",admin_login );
    if (!admin_password.isEmpty()) setting->setValue("MySQL/admin_password",admin_password );
    setting->sync();

    close();
    }

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Problem with QSettings

    This code will not even compile. In save_setting() function setting is defined as variable and later is used as if it is a pointer?
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. The following user says thank you to Santosh Reddy for this useful post:

    A_Stone (26th May 2013)

  4. #3
    Join Date
    May 2013
    Location
    Russia
    Posts
    4
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Problem with QSettings

    Quote Originally Posted by Santosh Reddy View Post
    This code will not even compile. In save_setting() function setting is defined as variable and later is used as if it is a pointer?
    You are right. Before my tried to change it's been like
    Qt Code:
    1. setting.setValue("MySQL/host", host);
    To copy to clipboard, switch view to plain text mode 
    But all the same Qsettings doesn't write new settings in ini-file

  5. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Problem with QSettings

    You are using a relative file path to the INI file. Make sure the working directory of the process is what you think it is.

  6. The following user says thank you to ChrisW67 for this useful post:

    A_Stone (26th May 2013)

  7. #5
    Join Date
    May 2013
    Location
    Russia
    Posts
    4
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Problem with QSettings

    Quote Originally Posted by ChrisW67 View Post
    You are using a relative file path to the INI file. Make sure the working directory of the process is what you think it is.
    In Qt 4.8 it works.In Qt5.0 I tried to write
    Qt Code:
    1. QString path = QApplication::applicationDirPath() + "/settings.ini"; QSettings setting(path, QSettings::IniFormat);
    To copy to clipboard, switch view to plain text mode 
    It did't help.

  8. #6
    Join Date
    May 2013
    Location
    Russia
    Posts
    4
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Problem with QSettings

    I solved the promblem. The programm was on a flash card. When I copied it on my computer, QSettings again started to work.

Similar Threads

  1. QSettings unicode problem
    By mgiza in forum Qt Programming
    Replies: 2
    Last Post: 3rd September 2011, 00:01
  2. QSettings problem!
    By 0xl33t in forum Newbie
    Replies: 5
    Last Post: 28th July 2009, 09:15
  3. QSettings problem
    By eleanor in forum Qt Programming
    Replies: 5
    Last Post: 4th May 2009, 15:11
  4. Problem with QSettings
    By arbi in forum Qt Programming
    Replies: 2
    Last Post: 24th September 2008, 09:49
  5. QSettings problem?
    By cyberboy in forum Qt Programming
    Replies: 2
    Last Post: 28th June 2008, 22:14

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.