McLan
McLan

Reputation: 2688

Qt: how to set QDate (that is converted from QString) on QDateEdit field?

I have a QDateEdit field on my mainwindow.

I capture whatever date is selected by the user as QString before insert it into the database.

QString membership_Date = ui->memebershipDate->text();

Then, in case the user want to update the date, I retrieve the QString date from the database. Here is the last step in the process to retrieve the date as QString (and after checking, the whole process always return the correct date):

QString date_temp = modelToShow->record(row_index).value(11).toString(); 

Then I convert the QString to QDate as follow:

QDate membership_Date = QDate::fromString(date_temp,"dd/MM/yyyy");

However, when I try to set the QDateEdit field using the following:

ui->memebershipDate->setDate(membership_Date);

It doesn't work and the QDateEdit never change and shows the default date.

How to set this right?

Upvotes: 0

Views: 1280

Answers (0)

Related Questions