[solved] - qdateedit editingfinished signal problem
-
have you experienced the following issue?
this is my code:
@void log::on_dateEdit_editingFinished()
{
QSqlDatabase h = QSqlDatabase::database("connection");
if (h.open())
{
QSqlQuery q1(h);
q1.prepare("SELECT * FROM log WHERE date>=:date1 AND date <=:date2 ORDER BY date ASC");
q1.bindValue(":date1" ,ui->date1->text());
q1.bindValue(":date2" ,ui->date2->text());
q1.exec();
QSqlQueryModel *mq1= new QSqlQueryModel();
mq1->setQuery(q1);
ui->tableView->setModel(mq1);
}
else
{
qDebug() << "connection is not opened" << h.lastError();
}
h.close();
}@1st time i run my application, after I edit date 2, the info is displayed correctly in my tableview.
if i close the session and run 2nd time the application, the query is not performed, or for some other reason no info is displayed in my tableview.have you experienced anything like this?
-
Hi,
You should also check that q1.exec() returns successfully
-
issue solved:
@ ...
q1.bindValue(":date1" ,ui->date1->text());
q1.bindValue(":date2" ,ui->date2->text());
...@should be: date() instead of text(), I guess the query will not consider the text as date.
correct code:
@...
q1.bindValue(":date1" ,ui->date1->date());
q1.bindValue(":date2" ,ui->date2->date());
...@thank you all for your input.