做C++ GUI Qt 3编程书中第二章快速对话框设计,GoToCell例子,同样出现第一个的问题,就是书中代码在我的程序中报错,下面具体叙述,请问是不是我的qt安装问题,某个库或什么的没有安装进去导致的报错?
1、designer作界面,连接槽

2、uic生成cpp和h文件
/*-------------------h--------------------------------*/
#ifndef GOTOCELLDIALOG_H
#define GOTOCELLDIALOG_H
#include <qvariant.h>
#include <qdialog.h>
class QVBoxLayout;
class QHBoxLayout;
class QGridLayout;
class QLabel;
class QLineEdit;
class QPushButton;
class GoToCellDialog : public QDialog
{
Q_OBJECT
public:
GoToCellDialog( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );
~GoToCellDialog();
QLabel* cellLocationLabel;
QLineEdit* lineEdit;
QPushButton* okButton;
QPushButton* cancelButton;
public slots:
virtual void enableOkButton();
protected:
QVBoxLayout* GoToCellDialogLayout;
QHBoxLayout* topLayout;
QHBoxLayout* bottomLayout;
protected slots:
virtual void languageChange();
private:
void init();
};
#endif // GOTOCELLDIALOG_H
/*--------------------cpp-----------------------*/
#include "gotocelldialog.h"
#include <qvariant.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <qpushbutton.h>
#include <qlayout.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include "gotocelldialog.ui.h"
/*
* Constructs a GoToCellDialog as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
*
* The dialog will by default be modeless, unless you set 'modal' to
* TRUE to construct a modal dialog.
*/
GoToCellDialog::GoToCellDialog( QWidget* parent, const char* name, bool modal, WFlags fl )
: QDialog( parent, name, modal, fl )
{
if ( !name )
setName( "GoToCellDialog" );
GoToCellDialogLayout = new QVBoxLayout( this, 11, 6, "GoToCellDialogLayout");
topLayout = new QHBoxLayout( 0, 0, 6, "topLayout");
cellLocationLabel = new QLabel( this, "cellLocationLabel" );
topLayout->addWidget( cellLocationLabel );
lineEdit = new QLineEdit( this, "lineEdit" );
topLayout->addWidget( lineEdit );
GoToCellDialogLayout->addLayout( topLayout );
bottomLayout = new QHBoxLayout( 0, 0, 6, "bottomLayout");
QSpacerItem* spacer = new QSpacerItem( 10, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
bottomLayout->addItem( spacer );
okButton = new QPushButton( this, "okButton" );
okButton->setEnabled( FALSE );
okButton->setDefault( TRUE );
bottomLayout->addWidget( okButton );
cancelButton = new QPushButton( this, "cancelButton" );
bottomLayout->addWidget( cancelButton );
GoToCellDialogLayout->addLayout( bottomLayout );
languageChange();
resize( QSize(232, 86).expandedTo(minimumSizeHint()) );
// signals and slots connections
connect( lineEdit, SIGNAL( textChanged(const QString&) ), this, SLOT( enableOkButton() ) );
connect( okButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
connect( cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
// buddies
cellLocationLabel->setBuddy( lineEdit );
init();}
/*
* Destroys the object and frees any allocated resources
*/
GoToCellDialog::~GoToCellDialog()
{
// no need to delete child widgets, Qt does it all for us
}
/*
* Sets the strings of the subwidgets using the current
* language.
*/
void GoToCellDialog::languageChange()
{
setCaption( tr( "Go to Cell" ) );
cellLocationLabel->setText( tr( "&Cell Location:" ) );
okButton->setText( tr( "OK" ) );
cancelButton->setText( tr( "Cancel" ) );
}
/*-------------------拷贝光盘中gotocelldialog.ui.h至工程代码如下-----------------*/
#include <qvalidator.h>
void GoToCellDialog::init()
{
QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}");
lineEdit->setValidator(new QRegExpValidator(regExp, this));
}
void GoToCellDialog::enableOkButton()
{
okButton->setEnabled(lineEdit->hasAcceptableInput());
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
3、progen生成pro,tmake生成Makefile
4、make后报错内容如下
gotocelldialog.ui.h: In member function `void GoToCellDialog::init()':
gotocelldialog.ui.h:6: parse error before `(' token
gotocelldialog.ui.h: In member function `virtual void
GoToCellDialog::enableOkButton()':
gotocelldialog.ui.h:11: invalid use of undefined type `struct QLineEdit'
gotocelldialog.h:20: forward declaration of `struct QLineEdit'
make: *** [gotocelldialog.o] Error 1
也就是这两句
lineEdit->setValidator(new QRegExpValidator(regExp, this));
okButton->setEnabled(lineEdit->hasAcceptableInput());
的问题,注释掉就没问题了,出现了和我的第一个问题类似
QHBox *hbox = new QHBox(0);报错
QHBox *hbox = new QHBox();不报错
这种问题是不是因为qt安装的问题呢?同学的机器上同样测试这段代码也报错,不知大家运行程序是否报错?或我这么写有什么问题吗?代码附上,请求大家帮助。