• 6297阅读
  • 9回复

求助!关于构造函数 [复制链接]

上一主题 下一主题
离线dxtus
 
只看楼主 倒序阅读 楼主  发表于: 2009-10-22
本人将<<C++ GUi Qt 4编程>>中的程序,在qdevolep中运行,结果就是出问题。我自己找半天实在找不出来,因为和原文对照着看,几乎是一样的。请各位兄台帮忙指出!
3Q!

问题就出在构造函数这几行,具体代码如下:
                       #include<QtGui>
                       #include "1.h"
              75    FindDialog::FindDialog(QWidget *parent)
              76              : QDialog(parent)
              77    {
                               lable=new QLable(tr("Find &What"));
                               lineedit=new LineEdit;
                                label->setBuddy (lineedit);
                                  ...
                         }

qdevolep编译出现的错误如下:
构建 (make)...
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Trolltech/Qt-4.3.0/mkspecs/linux-g++ -I. -I/usr/local/Trolltech/Qt-4.3.0/include/QtCore -I/usr/local/Trolltech/Qt-4.3.0/include/QtCore -I/usr/local/Trolltech/Qt-4.3.0/include/QtGui -I/usr/local/Trolltech/Qt-4.3.0/include/QtGui -I/usr/local/Trolltech/Qt-4.3.0/include -I. -I. -o 1.o src/1.cpp
src/1.cpp:76: ISO C++ forbids defining types within return type
src/1.cpp:76: `int' is not an aggregate type
src/1.cpp:76: semicolon missing after declaration of `class FindDialog'
src/1.cpp: In function `int FindDialog(QWidget*)':
src/1.cpp:77: only constructors take base initializers
src/1.cpp:77: confused by earlier errors, bailing out
make:
*** [1.o] Error 1

离线wato
只看该作者 1楼 发表于: 2009-10-22
丢了个分号吧..................
离线wsszlj

只看该作者 2楼 发表于: 2009-10-22
lable=new QLable(tr("Find &What"),this);
lineedit=new LineEdit(this);
离线dbzhang800

只看该作者 3楼 发表于: 2009-10-22
引用第1楼wato于2009-10-22 15:36发表的  :
丢了个分号吧..................


应该是这个了,楼主的头文件的类定义中估计忘记结尾的  分号 了

楼主不妨把头文件贴出来
离线dxtus
只看该作者 4楼 发表于: 2009-10-22
回各位,本人自己检查了N编,确实没发现少分号之类的错误。崩溃中!
现将全部文件贴出,请各位帮忙看看。谢谢!
1.h:


#ifndef _1_H
#define _1_H
#include<QDialog>
class QCheckBox;
class QLabel;
class QLineEdit;
class QPushButton;
class FindDialog: public QDialog
{
    Q_OBJECT
    public:
    FindDialog(QWidget *parent=0);
    signals:
    void findNext(const QString &str,Qt::CaseSensitivity CS);
    void findPrevious(const QString &str,Qt::CaseSensitivity CS);
    private slots:
    void findClicked();
    void enableFindButton(const QString &text);
    private:
    QLabel *label;
    QLineEdit *lineedit;
    QCheckBox *casecheckbox;
    QCheckBox *backwardcheckbox;
    QPushButton *findbutton;
    QPushButton *closebutton;
    
}

#endif


1.cpp:



#include<QtGui>
#include "1.h"
FindDialog::FindDialog(QWidget *parent)
: QDialog(parent)
{
            lable=new QLable(tr("Find &What"));
            lineedit=new LineEdit();
            label->setBuddy (lineedit);
            casecheckbox=new CheckBox(tr(Match &case));
            backwardCheckbox = new QCheckBox(tr("Search &backward"));
            findbutton=new QPushButton(tr(&Find));
            findbutton->setDefault(true);
            findbutton->setEnabled(false);
            closebutton = new QPushButton(tr("Close"));
            QObject::connect(lineedit,SIGNAL(textChanged(const Qstring &)),this,
            SLOT(enableFindButton(const Qtring &)));
            QObject::connect(findbutton,SIGNAL(clicked()),this,
            SLOT(findClicked()));
            connect (closeButton, SIGNAL(clicked()),
            this, SLOT(close ()));
            QHBoxLayout *lefttoplayout=new QHBoxLayout;
            lefttoplayout->addWidget(label);
            lefttoplayout->addWidget(lineedit);
            QVBoxLayout *leftlayout=new QVBoxLayout;
            leftlayout->addLayout(lefttoplayout);
            leftlayout->addWidget(casecheckbox);
            leftlayot->addWidget(backwardcheckbox);
            QHBoxLayout *rightLayout=new QHBoxLayout;
            rightlayout->addWidget(findbutton);
            rightlayout->addWidget(closebutton);
            rightlayout->addStretch();
            QHBoxLayout *mainlayout=new QHBoxLayout;
            mainlayout->addLayout(leftlayout);
            mainlayout->addLayout(rightlayout);
            this.setLayout(mainlayout);
            this.setWindowTitle(tr("Find"));
            this.setFixedHeight(sizeHint().height());    
            
}
          
           void FindDialog::findClicked()
           {
               QString text = lineEdit->text();
               Qt::CaseSensitivity cs =
             caseCheckBox->isChecked()?Qt::CaseSensitive
                                       : Qt::CaseInsensive;
           if  (backwardCheckBox->isChecked())
               {
                  emit findPrevious(text, cs);
               }
           Else
               {
                  emit findNext(text, cs);
               }
            
          }
          
          void FindDialog::enableFindButton(const QString &text)
          {
               findbutton->setEnabled(!text.isEmpty());
        }


main.cpp:


#include<QApplication>
#include "1.cpp"
int main(int argc, char *argv[])
{
     QApplication  app(argc, argv);
     FindDialog *dialog = new FindDialog;
     dialog->show();
     return  app.exec();
}
离线wato
只看该作者 5楼 发表于: 2009-10-23
class C
{

};
离线foxyz

只看该作者 6楼 发表于: 2009-10-23
class FindDialog: public QDialog
{
    Q_OBJECT
    public:
    FindDialog(QWidget *parent=0);
    signals:
    void findNext(const QString &str,Qt::CaseSensitivity CS);
    void findPrevious(const QString &str,Qt::CaseSensitivity CS);
    private slots:
    void findClicked();
    void enableFindButton(const QString &text);
    private:
    QLabel *label;
    QLineEdit *lineedit;
    QCheckBox *casecheckbox;
    QCheckBox *backwardcheckbox;
    QPushButton *findbutton;
    QPushButton *closebutton;
    
} ;                    ///这里的分号没了
只看该作者 7楼 发表于: 2009-10-23
casecheckbox=new CheckBox(tr(Match &case));这里面少了引号吧(tr(“Match &case”));
只看该作者 8楼 发表于: 2009-10-23
还有这里的引号也没加  findbutton=new QPushButton(tr(&Find));
离线jorneyr

只看该作者 9楼 发表于: 2009-10-23
class FindDialog: public QDialog
{
    Q_OBJECT
    public:
    FindDialog(QWidget *parent=0);
    signals:
    void findNext(const QString &str,Qt::CaseSensitivity CS);
    void findPrevious(const QString &str,Qt::CaseSensitivity CS);
    private slots:
    void findClicked();
    void enableFindButton(const QString &text);
    private:
    QLabel *label;
    QLineEdit *lineedit;
    QCheckBox *casecheckbox;
    QCheckBox *backwardcheckbox;
    QPushButton *findbutton;
    QPushButton *closebutton;
    
} // 这里少了分号

#endif
快速回复
限100 字节
 
上一个 下一个