首页| 论坛| 消息

标题:刚学Qt写的代码.....出错在哪里?
作者:style
日期:2006-05-15 16:12
内容:

#include
#include
#include
#include
#include
#include
class Clock:public QWidget
{
Q_OBJECT;
public:
Clock(QWidget *parent = NULL, const char *name = NULL);
public slots:
void TimeChange();

private:
QPushButton *exit;
QLabel *labSee;
struct tm *ti;
char timeStr[20];
};
Clock::Clock(QWidget *parent, const char *name):QWidget(parent, name)
{
setGeometry(100, 100, 200, 120);
setMinimumSize(200,120);
setMaximumSize(400,240);
labSee = new QLabel(this);
exit = new QPushButton("exit",this);
exit->setFont(QFont("Times",18,QFont::Bold));
connect(exit,SIGNAL(clicked()),qApp,SLOT(quit()));
TimeChange();
QTimer *timer = new QTimer;
timer->changeInterval(1000);
connect(timer,SIGNAL(timerout()),this,SLOT(TimeChange()));
timer->start(1000);
}


void Clock::TimeChange()
{
time_t t = time(NULL);
ti = localtime(&t);
sprintf(timeStr,"Time:%-2d,%-2d,%-2d",ti->tm.hour,ti->tm.min,ti->tm.sec);
labSee->setText(timeStr);
labSee->setAlignment(AlignCenter);
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Clock clock_c;
clock_c.show();
return a.exec();
}


#1 [kongfanxin 05-15 16:42]
能不能把编译出错信息给看一下 ?还有就是qt的版本?
#2 [style 05-15 17:40]
oot@style:~# cd Desktop/qq
root@style:~/Desktop/qq# rm kd.cpp~
root@style:~/Desktop/qq# qmake -project
root@style:~/Desktop/qq# qmake
root@style:~/Desktop/qq# make
g++ -c -pipe -Wall -W -O2-DQT_NO_DEBUG -DQT_SHARED -DQT_THREAD_SUPPORT -I/usr/lib/qt/mkspecs/default -I. -I. -I/usr/lib/qt/include -o kd.o kd.cpp
kd.cpp: In constructor `Clock::Clock(QWidget*, const char*)':
kd.cpp:37: error: `changelnterval' undeclared (first use this function)
kd.cpp:37: error: (Each undeclared identifier is reported only once for each
function it appears in.)
kd.cpp:39: error: no matching function for call to `QTimer::start()'
/usr/lib/qt/include/qtimer.h:55: error: candidates are: int QTimer::start(int,
bool)
kd.cpp: In member function `void Clock::TimeChange()':
kd.cpp:46: error: invalid use of `struct tm'
kd.cpp:46: error: invalid use of `struct tm'
kd.cpp:46: error: invalid use of `struct tm'
make: *** 错误 1
root@style:~/Desktop/qq#


Qt4.1.2
#3 [style 05-15 19:02]
root@style:~/Desktop/qq# make
g++ -c -pipe -Wall -W -O2-DQT_NO_DEBUG -DQT_SHARED -DQT_THREAD_SUPPORT -I/usr/lib/qt/mkspecs/default -I. -I. -I/usr/lib/qt/include -o q.o q.cpp
q.cpp: In member function `void Clock::TimeChange()':
q.cpp:49: error: invalid use of `struct tm'
q.cpp:49: error: invalid use of `struct tm'
q.cpp:49: error: invalid use of `struct tm'
make: *** 错误 1
root@style:~/Desktop/qq#

这是最后的结果...
好像提示能用strut tm结构体?这可是time.h头文件中的结构体啊...怎么..
#4 [newhappy 05-15 23:25]
你是刚学的么?
那么复杂

回复 发表
主题 版块