Problem with QDateTime
-
Hello everybody,
I am a beginner in Qt and i wrote my first code to make some tests.
I used the objects QDate or QTime without problems, but the object QDateTime doesn't work : whatever I do with it, the dateTime of my value is Thu 15. Oct 00:00:00 (even if I use the function currentDate()).Have you idees about my problem ?
Here is my code :
@QFile file(fileName);
file.open(QIODevice::ReadOnly);
QTextStream flux(&file);QString line;
QStringList tempArray;
QString stringDateTime;
QDate currDate;
QTime currTime;
QDateTime currDateTime;while(! flux.atEnd())
{
line = flux.readLine();
tempArray = line.split(',');currDate = QDate::fromString(tempArray[0], "dd/MM/yyyy");
currTime = QTime::fromString(tempArray[1], "hh:mm:ss");stringDateTime = tempArray[0] + " " + tempArray[1];
currDateTime = QDateTime::fromString(stringDateTime, "dd/MM/yyyy hh:mm:ss");
}
@Thanks !
-
Hi,
what is your code Output?
Running this code (very like to yours)
@
#include <QCoreApplication>#include <QDateTime>
#include <QStringList>#include <QtDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);QStringList lines; lines << "01/01/2013,10:10:13" << "01/12/2013,01:12:55" << "01/12/2013,01:13:55" << "01/12/2013,01:14:55" << "01/12/2013,01:15:55"; QStringList tempArray; QString stringDateTime; QDate currDate; QTime currTime; QDateTime currDateTime; Q_FOREACH (QString line, lines) { tempArray = line.split(','); currDate = QDate::fromString(tempArray[0], "dd/MM/yyyy"); currTime = QTime::fromString(tempArray[1], "hh:mm:ss"); qDebug() << currDate; qDebug() << currTime; stringDateTime = tempArray[0] + " " + tempArray[1]; currDateTime = QDateTime::fromString(stringDateTime, "dd/MM/yyyy hh:mm:ss"); qDebug() << currDateTime; } return 0;
// return a.exec();
}
@I get this output
@
QDate("mar gen 1 2013")
QTime("10:10:13")
QDateTime("mar 1. gen 10:10:13 2013")
QDate("dom dic 1 2013")
QTime("01:12:55")
QDateTime("dom 1. dic 01:12:55 2013")
QDate("dom dic 1 2013")
QTime("01:13:55")
QDateTime("dom 1. dic 01:13:55 2013")
QDate("dom dic 1 2013")
QTime("01:14:55")
QDateTime("dom 1. dic 01:14:55 2013")
QDate("dom dic 1 2013")
QTime("01:15:55")
QDateTime("dom 1. dic 01:15:55 2013")
@EDIT: Only to specify that the output string are in Italian Language