Double Spin Box Save to the file
-
I have 2 labels and 2 double spinbox. I want to save my datas a txt file which i changed them on double spinbox. How can i do it?
-
@suslucoder
Put slot on void void QDoubleSpinBox::valueChanged(double d) (or possibly ontextChanged
instead/as well, depends what you want).Oh, that was assuming your question meant "save to file as soon as the user changes the value in one of the spin boxes". If you just mean there is a Save button, then in the slot for it being clicked simply pick up the current values from the spin boxes and save them to file, nothing else to say.
-
Assuming these are application settings (for your
QChart
axis), you can useQSettings
If not, do as @JonB suggested:
Just take the current values from your spinBoxes and write them to your file, when pressing the
Save
-button (in a slot connected to buttonclicked
signal). -
@Pl45m4 I did it in that way. But in the future i will have more than 50 lineEdit.
Is there any easy way to do it?QFile file("/home/veriler.txt"); file.open(QIODevice::WriteOnly | QIODevice::Text); QApplication::processEvents(); QString nktkabul; nktkabul= ui->nktKbl->text(); QString mingorv; mingorv = ui->minGrv->text(); QTextStream out(&file); out<<nktkabul << mingorv;
-
@suslucoder said in Double Spin Box Save to the file:
QApplication::processEvents();
Remove this.
But in the future i will have more than 50 lineEdit.
Set up to use QDataWidgetMapper, which includes moving your data to a model. Or set up an array whose elements point to the data/widgets, so that you can iterate through them. Which is what a
QDataWidgetMapper
does anyway. -
@suslucoder said in Double Spin Box Save to the file:
Is it possible to do it?
Is it possible to do what?
The fact that you divide your UI so that the data is presented on separate tabs/pages (which is fine) has nothing to do with whether it is possible to save data, nor whether you might adopt a
QDataWidgetMapper
approach.