I want to write a code that increases the value in the line edit when the checkbox is clicked.
-
You do realize that between the wiki page @JonB linked to that is doing what you and the "restoring the state of a GUI application" example of the QSettings class, you have everything you need to write that part for your application ?
-
void Widget::on_mt_IncreaseValueButton_clicked()
{
auto originalLength = ui->mt_SerialNumberLineEdit->text().length();
auto val = ui->mt_SerialNumberLineEdit->text().toInt();
val += ui->mt_SpinBox->value();
ui->mt_SerialNumberLineEdit->setText(QString::number(val));
ui->mt_SerialNumberLineEdit->setText(QString::number(val).rightJustified(originalLength , '0'));
}How can I print and read the val variable here in the file ? I also want it to overwrite the value continuously.
-
-
bool WriteFile(){
QFile file("mt_SerialNumber.txt"); QTextStream stream(&file); while(val != NULL) { stream << QString::number(val); } return true;}
I defined something like this to main.cpp, but it says undeclared identifier because I can't pull val
-
Do you even read what we write?
I defined something like this to main.cpp, but it says undeclared identifier because I can't pull val
Because you probably dont have
valin yourmain.cpp. Return it there from your object instance of your widget. -
@wtimm said in I want to write a code that increases the value in the line edit when the checkbox is clicked.:
how can I extract the value from the file
open the file and read the content maybe?
-

By pressing the grab data button, the value in the serial number
I am printing to text file
when i reopen the project or widget again how can I extract the value from the file and show it in the serial number line edit every time?
@wtimm
It's just the same as where we advised you to useQSettingsfor this from the start. It is simply (a bit) more complicated with saving to a file yourself. You will still have to write just the same type of code to read the saved value and set into your line edit. -
QFile inputFile(QString("C:/Users/Hakan/Desktop/Qt Businees/da/mt_SerialNumber.txt")); inputFile.open(QIODevice::ReadOnly); if (!inputFile.isOpen()) return; QTextStream stream(&inputFile); for (QString line = stream.readLine(); !line.isNull(); line = stream.readLine()) { /* process information */ };I wrote a code like this but i couldn't get it to print serial number automatically(when i reopen the widget or project)