I want to write a code that increases the value in the line edit when the checkbox is clicked.
-
@wtimm said in I want to write a code that increases the value in the line edit when the checkbox is clicked.:
if i use originalLength function i got use of undeclared identifier 'originalLength' error
@J-Hilk said in I want to write a code that increases the value in the line edit when the checkbox is clicked.:
auto originalLength = ui->lineEdit->text().length();
ui->lineEdit->setText(QString::number(val).rightJustified(originalLength, '0'));
It's not a "function". So how did you get "undeclared identifier"?
-
int v = settings.value(number(val),defaultValue).toInt();
I wrote such a code but it didn't work.
When I save the increased value, how can I make the increased value show as default when I open the project again?@wtimm said in I want to write a code that increases the value in the line edit when the checkbox is clicked.:
When I save the increased value, how can I make the increased value show as default when I open the project again?
Save the increased (always the current) value when you close your project?!
-
int v = settings.value(number(val),defaultValue).toInt();
I wrote such a code but it didn't work.
When I save the increased value, how can I make the increased value show as default when I open the project again?@wtimm said in I want to write a code that increases the value in the line edit when the checkbox is clicked.:
I wrote such a code but it didn't work.
Meaning what? Please don't just say "it didn't work" if you want people to understand enough to help. Your code shows reading back a value. How do we know what you saved where how? Did you look in the external INI file or Windows Registry to see what is there which has been saved?
When I save the increased value, how can I make the increased value show as default when I open the project again?
Read it back in somewhere at startup and set the widget's value from the previously saved.
-
@wtimm said in I want to write a code that increases the value in the line edit when the checkbox is clicked.:
When I save the increased value, how can I make the increased value show as default when I open the project again?
Save the increased (always the current) value when you close your project?!
-
@wtimm Already told you to save it via
QSettings
, there really isn't anything else to say....@JonB we have defined the variable val in the above answers (the value in the line edit)
Can we do it if we define val inside the setValue function or should we do it using another function?
void Widget::on_grabDataButton_clicked()
{
QSettings settings;
settings.setValue("val",1);
settings.value("val").toInt();
} -
@JonB we have defined the variable val in the above answers (the value in the line edit)
Can we do it if we define val inside the setValue function or should we do it using another function?
void Widget::on_grabDataButton_clicked()
{
QSettings settings;
settings.setValue("val",1);
settings.value("val").toInt();
}@wtimm said in I want to write a code that increases the value in the line edit when the checkbox is clicked.:
void Widget::on_grabDataButton_clicked()
{
QSettings settings;
settings.setValue("val",1);
settings.value("val").toInt();
}Dont know what this should do. Maybe you are using
QSettings
wrong.To set value
settings.setValue("val", 42);
To read the value:
int val = settings.value("val").toInt();
And do whatever you like with
val
(set it to your line edit after you start your program) -
@wtimm Already told you to save it via
QSettings
, there really isn't anything else to say.... -
void Widget::on_grabDataButton_clicked()
{
}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'));
}
QSettings settings;
settings.setValue("val",42);
settings.value("val").toInt();where should i use code in
-
void Widget::on_grabDataButton_clicked()
{
}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'));
}
QSettings settings;
settings.setValue("val",42);
settings.value("val").toInt();where should i use code in
@wtimm said in I want to write a code that increases the value in the line edit when the checkbox is clicked.:
where should i use code in
Not in your buttonClicked handlers.
You save the current value one time, when you close your program and read it one time to write it back to your lineEdit, when you start your program.
e.g. your D'tor to save your value (obviously before you destroy your GUI) and maybe
showEvent()
to read your settings. -
@wtimm said in I want to write a code that increases the value in the line edit when the checkbox is clicked.:
I wrote such a code but it didn't work.
Meaning what? Please don't just say "it didn't work" if you want people to understand enough to help. Your code shows reading back a value. How do we know what you saved where how? Did you look in the external INI file or Windows Registry to see what is there which has been saved?
When I save the increased value, how can I make the increased value show as default when I open the project again?
Read it back in somewhere at startup and set the widget's value from the previously saved.
@JonB said in I want to write a code that increases the value in the line edit when the checkbox is clicked.:
When I save the increased value, how can I make the increased value show as default when I open the project again?
Read it back in somewhere at startup and set the widget's value from the previously saved.
-
void Widget::on_grabDataButton_clicked()
{
}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'));
}
QSettings settings;
settings.setValue("val",42);
settings.value("val").toInt();where should i use code in
Hi,
@wtimm said in I want to write a code that increases the value in the line edit when the checkbox is clicked.:
settings.value("val").toInt();
What exactly do you think that line is doing ?
How can it change anything with regards to your widgets ? -
As others have already written:
- read the settings into a variable
- do any computation you might need (it might be none)
- set the result on the widget that is supposed to contain it