初學QT編程

來源:互聯網
上載者:User

昨天編寫了一個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);
}

 

編譯出錯: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檔案加進去

其實只要認真看一下出錯提示,很快就改正過來了,可是我卻急著上網查相關的問題,結果很多方法都不行!所以說遇到問題,還是先根據出錯提示,審查一遍自己的代碼!

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.