• 6036阅读
  • 4回复

刚学Qt写的代码.....出错在哪里? [复制链接]

上一主题 下一主题
离线style
 
只看楼主 倒序阅读 楼主  发表于: 2006-05-15
#include <qapplication.h>
#include <qpushbutton.h>
#include <qfont.h>
#include <qlabel.h>
#include <time.h>
#include <qtimer.h>

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();
}
[ 此贴被style在2006-05-15 19:03重新编辑 ]
离线kongfanxin

只看该作者 1楼 发表于: 2006-05-15
能不能把编译出错信息给看一下 ?还有就是qt的版本?
kongfanxin
离线style
只看该作者 2楼 发表于: 2006-05-15
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: *** [kd.o] 错误 1
root@style:~/Desktop/qq#




Qt4.1.2
离线style
只看该作者 3楼 发表于: 2006-05-15
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: *** [q.o] 错误 1
root@style:~/Desktop/qq#


这是最后的结果...
好像提示能用strut tm结构体? 这可是time.h头文件中的结构体啊...怎么..
离线newhappy
只看该作者 4楼 发表于: 2006-05-15
你是刚学的么?
那么复杂
快速回复
限100 字节
 
上一个 下一个