[Qt-interest] Strange problem storing and retrieving and comparing QTime/QDataTime
Mihail Naydenov
mlists at ymail.com
Tue Nov 17 11:37:21 CET 2009
Hi
I have a small but annoying problem:
I create a table (in sqlite db):
"CREATE TABLE tbl ( id integer primary key autoincrement, lastmod );"
Then store a file`s last mod date:
QSqlQuery q;
q.prepare( "INSERT INTO metadata VALUES( :id, :lastmod )" );
q.bindValue("id",QVariant());
q.bindValue("lastmode", file.lastModified());
q.exec();
Later retrieve the values from both, again the file, and the db:
QSqlTableModel tbl;
tbl.setTable("metadata");
QDateTime lastmod = tbl.data(tbl.index(row, tbl.fieldIndex("lastmod"))).toDateTime();
QDateTime currlastmod = file.lastModified();
Now, the problem is, if I compare
lastmod == currlastmod
it *should* return true (the files are not changed indeed)
but in reality the test fails!
The interesting part is that if I convert both to string
lastmod.toString(Qt::ISODate) == currlastmod.toString(Qt::ISODate)
The test passes (as it should)
Also *only the QTime part fails*! This is
lastmod.date() == currlastmod.date()
also passes, but lastmod.time() == currlastmod.time() does not.
(Again if I toString() them they pass)
This happens for all DateFormats I tied, and all methods of storing to the database.
Any insights?
Thanks
MihailNaydenov
More information about the Qt-interest-old
mailing list