• 7625阅读
  • 9回复

新手求助!!郁闷啊 [复制链接]

上一主题 下一主题
离线yishu
 
只看楼主 倒序阅读 楼主  发表于: 2009-03-09
按照书上写的程序,却总是出错,请教各位高人:
自动生成的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
怎么回事啊?求助啊!
离线phpower
只看该作者 1楼 发表于: 2009-03-09
是不是和namespace有关系呢?
离线yishu
只看该作者 2楼 发表于: 2009-03-09
namespace怎么了啊?不懂唉
离线daimon0316
只看该作者 3楼 发表于: 2009-03-09
看不出来,不过错误提示说你那两个button没定义
博客地址 http://blog.sina.com.cn/daimon0316
离线浪漫天使
只看该作者 4楼 发表于: 2009-03-09
class GoToCellDiaolog 里面的 是 GoToCellDiaolog
GoToCellDialog(QWidget *parent=0); 里面的是  GoToCellDialog

比较一下 GoToCellDiaolog 与 GoToCellDialog!!!
发现什么了,别出声哦。。。。
离线yishu
只看该作者 5楼 发表于: 2009-03-09
谢谢楼上的,真是慧眼啊,呵呵。
改完之后还是出错唉,为什么啊::
gotocelldialog.cpp: In constructor `GoToCellDialog::GoToCellDialog(QWidget*)':
gotocelldialog.cpp:8: `clicked' undeclared (first use this function)
gotocelldialog.cpp:8: (Each undeclared identifier is reported only once for
   each function it appears in.)
gotocelldialog.cpp:8: `SINGAL' undeclared (first use this function)
gotocelldialog.cpp: In member function `void
   GoToCellDialog::on_lineEdit_textChanged()':
gotocelldialog.cpp:13: no matching function for call to `QPushButton::setEnable
   (bool)'
make: *** [gotocelldialog.o] Error 1
离线deepmind
只看该作者 6楼 发表于: 2009-03-09
不都写的那么清楚了,自己要认真点看看编译出错的信息
比如gotocelldialog.cpp:8: `clicked' undeclared (first use this function)
你看你UI_GOTOCELL_H里面都没定义
离线浪漫天使
只看该作者 7楼 发表于: 2009-03-09
SINGAL ->>>>>>>>>>>>SIGNAL。。。。
离线yishu
只看该作者 8楼 发表于: 2009-03-09
谢谢楼上的,真是慧眼啊,呵呵。
改完之后还是出错唉,为什么啊::
gotocelldialog.cpp: In constructor `GoToCellDialog::GoToCellDialog(QWidget*)':
gotocelldialog.cpp:8: `clicked' undeclared (first use this function)
gotocelldialog.cpp:8: (Each undeclared identifier is reported only once for
   each function it appears in.)
gotocelldialog.cpp:8: `SINGAL' undeclared (first use this function)
gotocelldialog.cpp: In member function `void
   GoToCellDialog::on_lineEdit_textChanged()':
gotocelldialog.cpp:13: no matching function for call to `QPushButton::setEnable
   (bool)'
make: *** [gotocelldialog.o] Error 1
离线yishu
只看该作者 9楼 发表于: 2009-03-09
谢谢你们,弄好了,都是单词拼错了,以后小心点
快速回复
限100 字节
 
上一个 下一个