我想提取系统时间,得到三个时间参数,然后现是用QLineEdit显示,该怎样做?我的老出错。下面使我写的
mytime.h
#include <QTime>
#include <QtGui>
#include <QDialog>
#include <QString>
#include <QLineEdit>
#include <QMainWindow>
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时,编译说没有此文件啊?谢谢大家。
[ 此贴被XChinux在2006-11-20 16:48重新编辑 ]