Open date in .txt in DateEdit Qt C ++
I am trying to save to .txt a DataEdit date in QtDesigner and then open the .txt and put the date in DataEdit.
save - okey:
QTextStream out(&sFile);
out << ui.lineEdit_2->text()<< "\n"
<< ui.lineEdit->text()<< "\n"
<< ui.dateEdit->text();
Open (this is the problem):
QTextStream in(&sFile);
QString text = in.readLine();
QString name = in.readLine();
QDateEdit fecha = in.readLine();
sFile.close();
ui.lineEdit_2->setText(text);
ui.lineEdit->setText(name);
ui.dateEdit->date(fecha);
Error 1 error C2440: "initialization": cannot convert from "QString" to "QDateEdit"
Error 2 errors C2660: "QDateTimeEdit :: date": function does not accept 1 argument
I don't know how to change this.
+3
source to share
3 answers
QDateEdit is a widget, not a QDate and QDate can be serialized, which the widget doesn't make sense to serialize - you are actually writing down the QDateEdit text and want to create a QDateEdit from that text.
Instead, you need to serialize the QDate of that edit and then return the QDate and set it to ui.dateEdit.
+1
source to share