【IT168 文档】昨天编写了一个qt计时器小程序,但是出现了个错误,直接今天才找出来!
/****************************************************************************
** Form implementation generated from reading ui file 'timer.ui'
**
** Created: Sun Mar 28 20:50:13 2010
** by: The User Interface Compiler (uic)
**
** WARNING! All changes made in this file will be lost!
****************************************************************************/
#include "timer.h"
#include <qlabel.h>
#include <qlineedit.h>
#include <qwidget.h>
#include <qlayout.h>
#include <qvariant.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include <qtimer.h>
/*
* Constructs a Form1 which is a child of 'parent', with the
* name 'name' and widget flags set to 'f'
*
* The wizard will by default be modeless, unless you set 'modal' to
* TRUE to construct a modal wizard.
*/
Form1::Form1( QWidget* parent, const char* name, bool modal, WFlags fl )
: QWizard( parent, name, modal, fl )
{
if ( !name )
setName( "Form1" );
resize( 596, 480 );
setCaption( tr( "timer" ) );
page = new QWidget( this, "page" );
TextLabel1 = new QLabel( page, "TextLabel1" );
TextLabel1->setGeometry( QRect( 404, 167, 91, 31 ) );
TextLabel1->setText( tr( "jishiqi" ) );
LineEdit1 = new QLineEdit( page, "LineEdit1" );
LineEdit1->setGeometry( QRect( 384, 217, 131, 41 ) );
addPage( page, tr( "Page" ) );
QTimer *timer=new QTimer(this,"timer");
connect(timer,SIGNAL(timeout()),this,SLOT(timerdone()));
timer->start(1000,TRUE);
}
/*
* Destroys the object and frees any allocated resources
*/
Form1::~Form1()
{
// no need to delete child widgets, Qt does it all for us
}
void Form1::timerdone()
{
char b[9]={'0','0',':','0','0',':','0','0','\0'};
if(b[7]!='9')
b[7] +=1;
else
b[7]='0';
if(b[6]!='5')
b[6] +=1;
else
b[6]='0';
if(b[4]!='9')
b[4] +=1;
else
b[4]='0';
if(b[3]!='5')
b[3] +=0;
else
b[3]='0';
if(b[0]!='2'&&b[1]!='9')
b[1] +=1;
else if(b[0]!='2'&&b[1]=='9')
{b[1]='0';b[0] +=1;}
else if(b[0]=='2'&&b[1]!='3')
b[1] +=1;
else
{b[0]='0';b[1]='0';}
LineEdit1->setTest(b);
}
** Form implementation generated from reading ui file 'timer.ui'
**
** Created: Sun Mar 28 20:50:13 2010
** by: The User Interface Compiler (uic)
**
** WARNING! All changes made in this file will be lost!
****************************************************************************/
#include "timer.h"
#include <qlabel.h>
#include <qlineedit.h>
#include <qwidget.h>
#include <qlayout.h>
#include <qvariant.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include <qtimer.h>
/*
* Constructs a Form1 which is a child of 'parent', with the
* name 'name' and widget flags set to 'f'
*
* The wizard will by default be modeless, unless you set 'modal' to
* TRUE to construct a modal wizard.
*/
Form1::Form1( QWidget* parent, const char* name, bool modal, WFlags fl )
: QWizard( parent, name, modal, fl )
{
if ( !name )
setName( "Form1" );
resize( 596, 480 );
setCaption( tr( "timer" ) );
page = new QWidget( this, "page" );
TextLabel1 = new QLabel( page, "TextLabel1" );
TextLabel1->setGeometry( QRect( 404, 167, 91, 31 ) );
TextLabel1->setText( tr( "jishiqi" ) );
LineEdit1 = new QLineEdit( page, "LineEdit1" );
LineEdit1->setGeometry( QRect( 384, 217, 131, 41 ) );
addPage( page, tr( "Page" ) );
QTimer *timer=new QTimer(this,"timer");
connect(timer,SIGNAL(timeout()),this,SLOT(timerdone()));
timer->start(1000,TRUE);
}
/*
* Destroys the object and frees any allocated resources
*/
Form1::~Form1()
{
// no need to delete child widgets, Qt does it all for us
}
void Form1::timerdone()
{
char b[9]={'0','0',':','0','0',':','0','0','\0'};
if(b[7]!='9')
b[7] +=1;
else
b[7]='0';
if(b[6]!='5')
b[6] +=1;
else
b[6]='0';
if(b[4]!='9')
b[4] +=1;
else
b[4]='0';
if(b[3]!='5')
b[3] +=0;
else
b[3]='0';
if(b[0]!='2'&&b[1]!='9')
b[1] +=1;
else if(b[0]!='2'&&b[1]=='9')
{b[1]='0';b[0] +=1;}
else if(b[0]=='2'&&b[1]!='3')
b[1] +=1;
else
{b[0]='0';b[1]='0';}
LineEdit1->setTest(b);
}
编译出错:no matching function for call to 'QLineEdit::setTest(char[9])'
以上错误是由于把setText写成了setTest
改完后,编译又出错:/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../crt1.o(.text+0x18): In function `_start':
../sysdeps/i386/elf/start.S:77: undefined reference to `main'
collect2: ld returned 1 exit status
错误是由于在Makefile中我没把main.cpp文件加进去
其实只要认真看一下出错提示,很快就改正过来了,可是我却急着上网查相关的问题,结果很多方法都不行!所以说遇到问题,还是先根据出错提示,审查一遍自己的代码!