請問有人運行過第二個Samples(FindDialog)嗎?
我嘗試編譯第二個程式(FindDialog)時發生了下列錯誤訊息,請問各位大大有誰知道這個錯誤呢?
findDialog.obj : error LNK2001: 無法解析的外部符號 "public: virtual struct QMeta
Object const * __thiscall FindDialog::metaObject(void)const " (?metaObject@FindD
ialog@@UBEPBUQMetaObject@@XZ)
findDialog.obj : error LNK2001: 無法解析的外部符號 "public: virtual void * __thi
scall FindDialog::qt_metacast(char const *)" (?qt_metacast@FindDialog@@UAEPAXPBD
@Z)
findDialog.obj : error LNK2001: 無法解析的外部符號 "public: virtual int __thisca
ll FindDialog::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@F
indDialog@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
findDialog.obj : error LNK2001: 無法解析的外部符號 "public: static struct QMetaO
bject const FindDialog::staticMetaObject" (?staticMetaObject@FindDialog@@2UQMeta
Object@@B)
findDialog.obj : error LNK2019: 無法解析的外部符號 "protected: void __thiscall F
indDialog::findNext(class QString const &,bool)" (?findNext@FindDialog@@IAEXABVQ
String@@_N@Z) 在函式 "private: void __thiscall FindDialog::findClicked(void)" (?
findClicked@FindDialog@@AAEXXZ) 中被參考
findDialog.obj : error LNK2019: 無法解析的外部符號 "protected: void __thiscall F
indDialog::findPrev(class QString const &,bool)" (?findPrev@FindDialog@@IAEXABVQ
String@@_N@Z) 在函式 "private: void __thiscall FindDialog::findClicked(void)" (?
findClicked@FindDialog@@AAEXXZ) 中被參考
debug\FindDialog.exe : fatal error LNK1120: 6 個無法解析的外部符號
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 8\VC\BIN\l
ink.EXE"' : 傳回碼 '0x460'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 8\VC\BIN\n
make.exe"' : 傳回碼 '0x2'
Stop.
main.cpp程式源碼如下
#include <QApplication>
#include "finddialog.h"
int main(int argc,char *argv[])
{
QApplication app(argc,argv);
FindDialog *dialog = new FindDialog();
dialog->show();
return app.exec();
}
FindDialog.h源碼如下
#ifndef FINDDIALOG_H
#define FINDDIALOG_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,bool caseSensitive);
void findPrev(const QString &str,bool caseSensitive);
private slots:
void findClicked();
void enableFindButton(const QString &text);
private :
QLabel *label;
QLineEdit *lineEdit;
QCheckBox *caseCheckBox;
QCheckBox *backwardCheckBox;
QPushButton *findButton;
QPushButton *closeButton;
};
#endif
FindDialog.cpp程式源碼如下
#include <QCheckBox>
#include <QLabel>
#include <QLayout>
#include <QLineEdit>
#include <QPushButton>
#include "finddialog.h"
FindDialog :: FindDialog(QWidget *parent)
:QDialog(parent)
{
label = new QLabel(tr("Find &what"),this);
lineEdit = new QLineEdit(this);
label->setBuddy(lineEdit);
caseCheckBox= new QCheckBox(tr("Match &case"),this);
backwardCheckBox = new QCheckBox(tr("Search &backward"),this);
findButton = new QPushButton(tr("&Find"),this);
findButton->setDefault(true);
findButton->setEnabled(false);
closeButton = new QPushButton(tr("Close"),this);
connect(lineEdit,SIGNAL(textChange(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(1);
QHBoxLayout *mainLayout = new QHBoxLayout (this);
mainLayout ->setMargin(11);
mainLayout ->setSpacing(4);
mainLayout ->addLayout(leftLayout);
mainLayout ->addLayout(rightLayout);
setLayout(mainLayout );
setWindowTitle(tr("Find..."));
}
void FindDialog::findClicked()
{
QString text = lineEdit->text();
bool caseSensitive = caseCheckBox->isChecked();
if (backwardCheckBox->isChecked())
emit findPrev(text,caseSensitive);
else
emit findNext(text,caseSensitive);
}
void FindDialog::enableFindButton(const QString &text)
{
findButton ->setEnabled(!text.isEmpty());
}