Qtの例をコンパイルする際に問題が発生しましたqt 4秒版のC++ GUIプログラミング book on visual C++ express 2010.Since qt visual studio add-inが動作しませんExpress版では、ライブラリの依存関係を追加するだけで、自分で設定しました。qtmaind.lib QtCored4.lib QtGuid4.lib。また、サンプルコード「Hello、Qt!」をコンパイルできます。間違いなく。
findDialog.h:Visual StudioでQtの例をコンパイル中にリンクエラーが発生する
#ifndef FINDDIALOG_H
#define FINDDIALOG_H
#include <QtGui\qdialog.h>
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
findDialog.cpp:
#include <QtGui\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());
}
main.cppに:
#include <QtGui\qapplication.h>
#include <iostream>
#include "findDialog.h"
int main(int argc , char* argv[])
{
QApplication app(argc , argv);
findDialog* dialog = new findDialog;
dialog->show();
return app.exec();
}
I 私のプロジェクトには、2つの.cppファイルとヘッダファイルが含まれていますこのプロジェクトをコンパイルすると、6つのリンクエラーが発生します。
LNK2001:未解決の外部シンボル "パブリック:仮想構造体QMetaObjectのCONST * __thiscall findDialog ::メタオブジェクト(無効)constは、"(メタオブジェクト@ findDialog @@ UBEPBUQMetaObject @@ XZ?)
LNK2001:未解決の外部シンボル「パブリック:仮想無効* __thiscall findDialog :: qt_metacast(char型のconst *) "(qt_metacast @ findDialog @@ UAEPAXPBD @ Z?)
LNK2001:未解決の外部シンボル" パブリック:仮想int型__thiscall findDialog :: qt_metacall(列挙QMetaObject ::コール、int型ボイド* *)」?(qt_metacall @ findDialog @@ UAEHW4Call @ QMetaObject @@ HPAPAX @ Z)
LNK2001:未解決の外部シンボル "パブリック:?静的構造体QMetaObjectのconstのfindDialog :: staticMetaObject"(staticM etaObject @ findDialog @@ 2UQMetaObject @@ B)
LNK2019:未解決の外部シンボル? "保護:無効__thiscall findDialog ::のfindNext(クラスQStringののconstの&、列挙型はQt :: CaseSensitivity)"(のfindNext @ findDialog @@ IAEXABVQString @ @ W4CaseSensitivity Qtの機能の中で参照@@@ Z)@ "プライベート:無効__thiscall findDialog :: findClicked(無効)"(findClicked @ findDialog @@ AAEXXZ)
LNK2019:未解決の外部シンボル「保護されます。void __thiscall findDialog:関数 "private:void __thiscall findDialog :: findClicked(void)"で参照されるfindPrevious(クラスQString const &、列挙型Qt :: CaseSensitivity) "(findPrevious @ findDialog @@ IAEXABVQString @@ W4CaseSensitivity @ Qt @@@ Z) ?findClicked @ findDialog @@ AAEXXZ)
ありがとう、私の悪い英語のために申し訳ありません。
moc_findDialog.cppを生成しましたか? – werewindle
No.必要ですか? –