[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?
-
What is the debug output you've got with h.lastError()?
-
no error message, meaning the connection is opened.
-
Hi,
You should also check that q1.exec() returns successfully
-
Hi,
query returns successfully from Qt and PostgreSQL with required fields - values substitution. as mentioned, when i run 1st time after reboot the application, the query returns the correct values and tableview displays them.
-
I don't understand exactly the situation with all the rebooting and excetera; but I think it is strange you close the database connection at the end of the function. Isn't that your problem?
-
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.