SQL Data type error
-
Hello guys!
I have a problem with SQL Data for participants which is not being displayed correctly. I need to show the date & time (2016-04-16T16:22:32.604Z) which is a QDateTime and it shows itself up as "00:54:36.848" & a few Participant tags which are in hex value format and thus a QString but it is displayed as an integer.
I create my table in the ":memory" and the table code is as followsqry.prepare("CREATE TABLE IF NOT EXISTS participant (" "participant_id INTEGER PRIMARY KEY," "firstname VARCHAR(10)," "lastname VARCHAR(20)," "participant_tag VARCHAR(20)" "participant_time TIMESTAMP" ")");
This is how I am writing to the table
QSqlQuery qry; qry.prepare("insert into participant(firstname, lastname, participant_tag, participant_time)" " values(:firstname,:lastname, :participant_tag, :participant_time)"); qry.bindValue(":firstname", firstname); qry.bindValue(":lastname", lastname); qry.bindValue(":participant_tag", participant_tag); qry.bindValue(":participant_time", participant_time);
This is how I am displaying in the QTableView
QStandardItemModel *model = new QStandardItemModel(station1data.size(), 2,this); model->setHorizontalHeaderItem(0, new QStandardItem(QString("participant_id"))); model->setHorizontalHeaderItem(1, new QStandardItem(QString("participant_tag"))); model->setHorizontalHeaderItem(2, new QStandardItem(QString("participant_time"))); int n = 0; foreach(msg_station1data d, station1data) { QStandardItem *item = new QStandardItem(QString(d.participant_id)); model->setItem(n,0,item); item = new QStandardItem(QString(d.participant_tag)); model->setItem(n,1,item); item = new QStandardItem((d.participant_time).toString("hh:mm:ss.zzz")); model->setItem(n,2,item); ++n;
Any help suggestion is appreciated (Thanks!)
-
Hi,
For the date part, you are currently seeing what you are asking for (i.e. your format string).Take a look at the
.toString
funtion call.For the hex part, can you show an example ?
-
Then store the QDateTime value and create a small QStyledItemDelegate to show the date the way you want it.
How are you storing the hex values in the first place ?
-
You are writing that you want to show it like
2016-04-16T16:22:32.604Z
but later re-use it in another format. So either you store the QDateTime object and so you can re-use it and format it the way you want it when you want it. Or you store a string version of it and you'll have to re-do the conversion plus formatting later. -
What does work ?