Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Not able to save values.



  • Hello friends,I have written the below code to save my settings using qsettings and when i again open it,i should get the same state,but the values are not saved,,please help me out in this regard..

    @#include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QSettings>
    #include <QtCore/QCoreApplication>
    #include <QtGui/QCloseEvent>
    MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    // readSettings();
    // writeSettings();

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }void MainWindow::on_click_clicked()
    {
    ui->pushButton->setStyleSheet("color: red;");
    ui->pushButton_2->setStyleSheet("background-color: green;");
    ui->pushButton_3->setStyleSheet("background-color: yellow;");
    }
    void MainWindow::writeSettings()
    {
    QSettings settings("Moose Soft", "Clipper");

    settings.beginGroup("pushbutton");
    settings.setValue("size", size());
    settings.setValue("pos", pos());
    QColor r("red");
    r.name();
    settings.setValue("color",r.name());
    settings.endGroup();
    }

    void MainWindow::readSettings()
    {
    QSettings settings("Moose Soft", "Clipper");

    settings.beginGroup("pushbutton");
    resize(settings.value("size", QSize(400, 400)).toSize());
    move(settings.value("pos", QPoint(200, 200)).toPoint());
    QColor r(settings.value("color").toString());
    settings.endGroup();
    }
    void MainWindow::closeEvent(QCloseEvent * event)
    {
    if(on_exit_clicked())
    {
    writeSettings();
    event->accept();
    }
    else
    event->ignore();

    }

    bool MainWindow::on_exit_clicked()
    {
    writeSettings();
    exit(0);
    }@

    regards
    imrrk



  • Hello Andre please dont close this thread..



  • Closed as duplicate. This is the third thread to this topic from you now.


Log in to reply