按照书上写的程序,却总是出错,请教各位高人:
自动生成的ui_gotocell.h的内容为:
/********************************************************************************
** Form generated from reading ui file 'gotocell.ui'
**
** Created: Wed Mar 4
16:43:11 2009
** by: Qt User Interface Compiler version 4.4.3
**
** WARNING! All changes made in this file will be lost when recompiling ui file!
********************************************************************************/
#ifndef UI_GOTOCELL_H
#define UI_GOTOCELL_H
#include <QtCore/QVariant>
#include
<QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QDialog>
#include <QtGui/QFormLayout>
#include <QtGui/QGridLayout>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
#include <QtGui/QSpacerItem>
QT_BEGIN_NAMESPACE
class Ui_GoTOCellDialog
{
public:
QFormLayout *formLayout;
QGridLayout *gridLayout;
QLineEdit *lineEdit;
QSpacerItem *horizontalSpacer;
QPushButton *okButton;
QPushButton *cancelButton;
QLabel *label;
void setupUi(QDialog *GoTOCellDialog)
{
if (GoTOCellDialog->objectName().isEmpty())
GoTOCellDialog->setObjectName(QString::fromUtf8("GoTOCellDialog"));
GoTOCellDialog->resize(314, 252);
formLayout = new QFormLayout(GoTOCellDialog);
formLayout->setObjectName(QString::fromUtf8("formLayout"));
gridLayout = new QGridLayout();
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
lineEdit = new QLineEdit(GoTOCellDialog);
lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
gridLayout->addWidget(lineEdit, 0, 2, 1, 2);
horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
gridLayout->addItem(horizontalSpacer, 1, 0, 1, 1);
okButton = new QPushButton(GoTOCellDialog);
okButton->setObjectName(QString::fromUtf8("okButton"));
okButton->setEnabled(false);
okButton->setAutoDefault(false);
okButton->setDefault(true);
gridLayout->addWidget(okButton, 1, 1, 1, 2);
cancelButton = new QPushButton(GoTOCellDialog);
cancelButton->setObjectName(QString::fromUtf8("cancelButton"));
gridLayout->addWidget(cancelButton, 1, 3, 1, 1);
label = new QLabel(GoTOCellDialog);
label->setObjectName(QString::fromUtf8("label"));
gridLayout->addWidget(label, 0, 0, 1, 2);
formLayout->setLayout(0, QFormLayout::LabelRole, gridLayout);
#ifndef QT_NO_SHORTCUT
label->setBuddy(lineEdit);
#endif // QT_NO_SHORTCUT
retranslateUi(GoTOCellDialog);
QObject::connect(okButton, SIGNAL(clicked()), GoTOCellDialog, SLOT(accept()));
QObject::connect(cancelButton, SIGNAL(clicked()), GoTOCellDialog, SLOT(reject()));
QObject::connect(lineEdit,
SIGNAL(textChanged(QString)), GoTOCellDialog, SLOT(enableOkButton()));
QMetaObject::connectSlotsByName(GoTOCellDialog);
} // setupUi
void
retranslateUi(QDialog *GoTOCellDialog)
{
GoTOCellDialog->setWindowTitle(QApplication::translate("GoTOCellDialog", "Go to Cell", 0, QApplication::UnicodeUTF8));
okButton->setText(QApplication::translate("GoTOCellDialog", "OK", 0, QApplication::UnicodeUTF8));
cancelButton->setText(QApplication::translate("GoTOCellDialog", "Cancel", 0, QApplication::UnicodeUTF8));
label->setText(QApplication::translate("GoTOCellDialog", "&Cell Location:", 0, QApplication::UnicodeUTF8));
Q_UNUSED(GoTOCellDialog);
} // retranslateUi
};
namespace Ui {
class GoTOCellDialog: public
Ui_GoTOCellDialog {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_GOTOCELL_H
*******************gotocelldialog.h的内容为:
#ifndef GOTOCELLDIALOG_H
#define GOTOCELLDIALOG_H
#include<QtGui/QDialog>
#include"ui_gotocell.h"
class GoToCellDiaolog:public QDialog,public Ui::GoTOCellDialog
{
Q_OBJECT
public:
GoToCellDialog(QWidget *parent=0);
private slots:
void on_lineEdit_textChanged();
};
#endif
gotocelldialog.cpp内容为:
#include <QtGui>
#include "gotocelldialog.h"
GoToCellDialog::GoToCellDialog(QWidget *parent):QDialog(parent)
{
setupUi(this);
QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}");
lineEdit->setValidator(new QRegExpValidator(regExp,this));
connect(okButton,SINGAL(clicked()),this,SLOT(accept()));
connect(cancelButton,SIGNAL(clicked()),this,SLOT(reject()));
}
void GoToCellDialog::on_lineEdit_textChanged()
{
okButton->setEnable(lineEdit->hasAcceptableInput());
}
************************main.cpp的内容为:
#include <QtGui/QApplication>
#include "gotocelldialog.h"
int main(int argc,char *argv[])
{
QApplication a(argc,argv);
GoToCellDialog *dialog=new GoToDialog;
dialog->show();
return a.exec();
}
*******************运行之后错误如下:
In file included from gotocelldialog.cpp:2:
gotocelldialog.h:10: ISO C++ forbids declaration of `GoToCellDialog' with no
type
gotocelldialog.cpp:3: syntax error before `::' token
gotocelldialog.cpp:7: syntax error before `->' token
gotocelldialog.cpp:8: `okButton' was not declared in this scope
gotocelldialog.cpp:8: `clicked' was not declared in this scope
gotocelldialog.cpp:8: `SINGAL' was not declared in this scope
gotocelldialog.cpp:8: invalid use of `this' at top level
gotocelldialog.cpp:8: ISO C++ forbids declaration of `connect' with no type
gotocelldialog.cpp:8: initializer list being treated as compound expression
gotocelldialog.cpp:9: `cancelButton' was not declared in this scope
gotocelldialog.cpp:9: invalid use of `this' at top level
gotocelldialog.cpp:9: ISO C++ forbids declaration of `connect' with no type
gotocelldialog.cpp:9: redefinition of `int connect'
gotocelldialog.cpp:8: `int connect' previously defined here
gotocelldialog.cpp:9: initializer list being treated as compound expression
gotocelldialog.cpp:10: parse error before `}' token
gotocelldialog.cpp:11: syntax error before `::' token
{standard input}: Assembler messages:
{standard input}:19: Error: symbol `connect' is already defined
make: *** [gotocelldialog.o] Error 1
怎么回事啊?求助啊!