PDA

View Full Version : Milliseconds from QDateTime



scamE
12th September 2010, 18:16
Hi, all
I have code:


#include <QtGui/QApplication>
#include <QHBoxLayout>
#include <QLabel>
#include <QDateTime>
#include <QString>
#include <time.h>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget* w =new QWidget;
QHBoxLayout* lyaout = new QHBoxLayout;
QLabel* label;
time_t seconds;

QDateTime* date_f = new QDateTime;
QString milisec;
QString format="mmssz";
QString & need_f=format;
seconds=time(NULL);
date_f->setTime_t(seconds);
milisec=date_f->toString(need_f);

label = new QLabel(milisec);
lyaout->addWidget(label);

w->setWindowTitle("Try again");
w->setLayout(lyaout);
w->show();

return a.exec();
}


date_f->setTime_t(seconds) don't return time in milliseconds.
Why is? What method can return time in milliseconds?

Thanks.

wysota
12th September 2010, 18:25
Miliseconds will always be zero here because time() has a resolution of one second.

scamE
12th September 2010, 18:59
I thought about it. Ok, what function can return time with milliseconds?
My OS is Linux.

wysota
12th September 2010, 19:46
Try QDateTime::currentDateTime().