标题:如何显示时间
作者:zhendeyue
日期:2006-11-18 13:37
内容:
我想提取系统时间,得到三个时间参数,然后现是用QLineEdit显示,该怎样做?我的老出错。下面使我写的
mytime.h
#include
#include
#include
#include
#include
#include
int ihour;
int isecond;
int iminute;
class QString string;
class MyTime:public QMainWindow{
Q_OBJECT
public:
MyTime(QMainWindow *parent=0);
signals:
void timeChanged(QTime *time);
public slots:
void update(QTime *time);
private:
QTime time;
QLineEdit *mline;
};
mytime.cpp
#include "mytime.h"
MyTime::MyTime(QMainWindow *parent)
:QMainWindow(parent){
time=new QTime::currentTime();
ihour=time.hour();
isecond=time.second();
iminute=time.minute();
QSting string("%03d:%02d:%02d",ihour,isecond,iminute);
mline=new QLineEdit;
mline->setGeometry(1,1,15,15);
mline->setReadOnly(TRUE);
//mline->insert(&string);
connect(SIGNAL(timeChanged(QTime &time)),mline,SLOT(update(QTime &time)));
//connect(time,SIGNAL(timeChanged(QTime *)),this,SIGNAL(timeChanged(QTime *)));
}
void MyTime::update(QTime *time){
time=new QTime::currentTime();
ihour=time.hour();
isecond=time.second();
iminute=time.minute();
QString string("%03d:%02d:%02d",ihour,isecond,iminute);
mline->insert(&string);
emit timeChanged(QTime &time);
}
我刚开始学着写,错误很多,想通过这个跟大家学一下,好有为何我用QMultiLineEdit时,编译说没有此文件啊?谢谢大家。
#1 [cavendish 11-19 03:10]
QSting string("%03d:%02d:%02d",ihour,isecond,iminute);
玩qt这么多年了
也没见过这种用法呀
初学不怕
多看文档和实例
不要太想当然了
#2 [zhendeyue 11-20 13:42]
Sorry,I don't know how to use String to add my three parameters,ihour,isecond and iminute.
If someone can help me,please!
Thank you very much!
#3 [XChinux 11-20 16:48]
确一下Assistant中的QTime的文档
QTime::toString("hh:mm:ss")
#4 [zhendeyue 11-26 12:00]
Thank you XChinux,I don't know why in the past few days I can'tcome here,but I have resolved it:
QString string;
string = QString("%1:%2:%3").arg(ihour).arg(iminute).arg(isecond);
QLineEdit *line = new QLineEdit;
line -> setText(string);
That's ok!Now I have another question,I will send a new title,hope you can give me some advice,so that I can save much
time,Thank you very much!
#5 [XChinux 11-26 14:37]
登录不了qtcn.org可能是因为qtcn.org使用的新网DNS服务出现问题的缘故,所以你最好在自己机器上设置一下qtcn.org的DNS,这样就访问快多了。
请看一下这个帖子:
http://www.qtcn.org/bbs/read.php?tid=2285
改变窗体的title,可以用setWindowTitle(QString)这个方法。