PDA

View Full Version : How to Populate QDateEdit Stored in QString again into a QDateEdit



joyous_sidd
23rd January 2017, 06:48
I have 2 QDateEdit which are Date_dob and Date_doj.

I am storing the value using a Qstring shown below.

QString str_dob(ui->DATE_dob->text());
QString str_doj(ui->DATE_doj->text());

Now i want to populate the same into ui->Date_dob and ui->Date_doj (after some editing event takes place). I have used ,

ui->DATE_dob->setText(s.at(2));
ui->DATE_doj->setText(s.at(5)); //where s is a string having data

but the data doesnt polpulate.

Any kind of suggestion will be extremely appreicated.
Thanks in advance

anda_skoa
23rd January 2017, 09:58
You might have to parse the string into QDate object and pass that to the widget.
See QDate::fromString(), but also consider storing the dates as dates.

Cheers,
_

joyous_sidd
24th January 2017, 07:11
I will try this for sure. But problem is i m using txt file. and all read, write, edit and delete logic is done with QStrings and indexing which then populates in QTableWidget. This might invovle alot of changes throughout the code.

anda_skoa
24th January 2017, 09:13
Well in this case just format the date in a specific way and then use the same format for parsing it back.

I.e. QDate::toString() and QDate::fromString() with the same format.

Cheers,
_