Important: Please read the 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()

    void Dialog::saveValue()


    //QString path="/mnt/dr";
    QString path="/home/pi/QT-VS/hsv.txt";
    QFile valueHSV(path);
    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": then why do you use released() signal of "QAbstractButton":

    Try "QCheckBox::stateChanged(int state)": And write state into a file.

  • thx alot =)

Log in to reply