Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]how to save checkbox state as a value once checkbox is triggered?
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    YDYD
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • Y Offline
        Y Offline
        YDYD
        wrote on last edited by
        #3

        thx alot =)

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved