• 7168阅读
  • 3回复

Qt4书中一个例子,检查了半天也没查出错误,非常郁闷 [复制链接]

上一主题 下一主题
离线cnnbboy
 

只看楼主 倒序阅读 楼主  发表于: 2009-01-25
— 本帖被 XChinux 执行加亮操作(2009-01-26) —
书里面的第四里例子,前面几个都能很成功的运行,但这个却出现了错误,很郁闷,希望大家能帮助解决
代码如下:
#include <QtGui>

#include "finddialog.h"
FindDialog::FindDialog(QWidget *parent) : QDialog(parent)
{
    label = new QLabel(tr("Find &what:"));
    lineEdit = new QLineEdit;
    label->setBuddy(lineEdit);
   
    caseCheckBox = new QCheckBox(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"));
   
    connect(lineEdit,SIGNAL(textChanged(const QString &)),this,SLOT(enableFindButton(const QString &)));
    connect(findButton,SIGNAL(clicked()),this,SLOT(findClicked()));
    connect(closeButton,SIGNAL(clicked()),this,SLOT(close()));
   
    QHBoxLayout *topLeftLayout = new QHBoxLayout;
    topLeftLayout->addWidget(label);
    topLeftLayout->addWidget(lineEdit);
   
    QVBoxLayout *leftLayout = new QVBoxLayout;
    leftLayout->addLayout(topLeftLayout);
    leftLayout->addWidget(caseCheckBox);
    leftLayout->addWidget(backwardCheckBox);
   
    QVBoxLayout *rightLayout = new QVBoxLayout;
    rightLayout->addWidget(findButton);
    rightLayout->addWidget(closeButton);
    rightLayout->addStretch();
   
    QHBoxLayout *mainLayout = new QHBoxLayout;
    mainLayout->addLayout(leftLayout);
    mainLayout->addLayout(rightLayout);
    setLayout(mainLayout);
   
    setWindowTitle(tr("Find"));
    setFixedHeight(sizeHint().height());
}

void FindDialog::findClicked()
{
    QString text = lineEdit->text();
    Qt::CaseSensitivity cs = caseCheckBox->isChecked()?Qt::CaseSensitive:Qt::CaseInsensitive;
    if(backwardCheckBox->isChecked())
    {
        emit findPrevious(text,cs);
    }
    else
    {
        emit findNext(text,cs);
    }
}

void FindDialog::enableFindButton(const QString &text)
{
    findButton->setEnabled(!text.isEmpty());
}
调试信息如下:
4 E:\Dev-Cpp\Project\Ex4\finddialog.cpp new types may not be defined in a return type
4 E:\Dev-Cpp\Project\Ex4\finddialog.cpp return type specification for constructor invalid
E:\Dev-Cpp\Project\Ex4\Makefile.win [Build Error]  [finddialog.o] Error 1
我就很奇怪,为什么会出现这样的情况,调试信息看得懂,但解决不了
离线cnnbboy

只看该作者 1楼 发表于: 2009-01-25
解决了,竟然犯了非常初级的错误。。。
但又出现了新的错误
  [Linker error] undefined reference to `vtable for FindDialog'
  [Linker error] undefined reference to `FindDialog::findNext(QString const&, Qt::CaseSensitivity)'
等等。。。连接错误。。
用的是dev cpp+QT
如果用命令行则能正常执行
很奇怪
[ 此贴被cnnbboy在2009-01-25 17:22重新编辑 ]
离线iptton

只看该作者 2楼 发表于: 2009-02-03
make clean一下
[url] http://www.alloyteam.com/2012/05/web-front-end-tool-rythem-1/ [url]
离线wd007

只看该作者 3楼 发表于: 2009-02-09
看看你的环境变量设置,是不是你同时装了Qt3和Qt4,qmake的版本要用Qt4的
欢迎访问我的博客,一起学习提高
http://blog.csdn.net/qter_wd007
快速回复
限100 字节
 
上一个 下一个