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

[SOLVED]how to save checkbox state as a value once checkbox is triggered?



  • Hi all,
    I would like to save the state of the checkbox as 0 or 1 in a txt file.

    I did as below:

    @void Dialog::checkBox()
    {
    connect(ui->invertCheck,SIGNAL(released()),this,SLOT(saveValue()));
    }

    void Dialog::saveValue()

    {

    //QString path="/mnt/dr";
    
    
    
    QString path="/home/pi/QT-VS/hsv.txt";
    
    
    QFile valueHSV(path);
    
    
    valueHSV.open(QIODevice::WriteOnly);
    
    
    QTextStream hsv(&valueHSV);
    
    
    
    
    hsv << ui->hueSlide1->value() <<endl;
    
    
    hsv << ui->hueSlide2->value() <<endl;
    
    
    hsv << ui->satSlide1->value() <<endl;
    
    
    hsv << ui->satSlide2->value() <<endl;
    
    
    hsv << ui->lumSlide1->value() <<endl;
    
    
    hsv << ui->lumSlide2->value() <<endl;
    
    
    
    
    hsv << ui->invertCheck->isChecked() <<endl;
    
    
    qDebug()<< ui->invertCheck->isChecked();
    
    valueHSV.close(); //file closed
    

    }@

    My problem is:
    I can only save the state (0 or 1) into txt file once i move one of the slider, i check or uncheck, it does gv me any changes.
    How can I get 0 or 1 once I check or uncheck the check box.



  • If ui->invertCheck is "QCheckBox":http://qt-project.org/doc/qt-5/qcheckbox.html#details then why do you use released() signal of "QAbstractButton":http://qt-project.org/doc/qt-5/qabstractbutton.html

    Try "QCheckBox::stateChanged(int state)":http://qt-project.org/doc/qt-5/qcheckbox.html#stateChanged And write state into a file.



  • thx alot =)


Log in to reply