OS:windows xp SP2、コンパイラ:Code::Blocks ver. 10.05 、Qt 4.6
最近Qtを学び始めました。最初は、単純な tut の例でうまくいきました。すぐにコンパイルできない例に出くわし、何かがおかしいことに気づきました。
コードは次のとおりです。
#include <QWidget>
#include <QApplication>
#include <QPushButton>
#include <QLabel>
#include <QDesktopWidget>
class Communicate : public QWidget
{
Q_OBJECT
public:
Communicate(QWidget *parent = 0);
private slots:
void OnPlus();
void OnMinus();
private:
QLabel *label;
};
void center(QWidget *widget, int w, int h)
{
int x, y;
int screenWidth;
int screenHeight;
QDesktopWidget *desktop = QApplication::desktop();
screenWidth = desktop->width();
screenHeight = desktop->height();
x = (screenWidth - w) / 2;
y = (screenHeight - h) / 2;
widget->move( x, y );
}
Communicate::Communicate(QWidget *parent)
: QWidget(parent)
{
int WIDTH = 350;
int HEIGHT = 190;
resize(WIDTH, HEIGHT);
QPushButton *plus = new QPushButton("+", this);
plus->setGeometry(50, 40, 75, 30);
QPushButton *minus = new QPushButton("-", this);
minus->setGeometry(50, 100, 75, 30);
label = new QLabel("0", this);
label->setGeometry(190, 80, 20, 30);
connect(plus, SIGNAL(clicked()), this, SLOT(OnPlus()));
connect(minus, SIGNAL(clicked()), this, SLOT(OnMinus()));
center(this, WIDTH, HEIGHT);
}
void Communicate::OnPlus()
{
int val = label->text().toInt();
val++;
label->setText(QString::number(val));
}
void Communicate::OnMinus()
{
int val = label->text().toInt();
val--;
label->setText(QString::number(val));
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Communicate window;
window.setWindowTitle("Communicate");
window.show();
return app.exec();
}
開こうとすると、次のメッセージが表示されます。
obj\リリース\main.o:main.cpp|| 「通信用 vtable」への未定義参照 |
obj\リリース\main.o:main.cpp|| 「通信用 vtable」への未定義参照 |
obj\リリース\main.o:main.cpp|| 「通信用 vtable」への未定義参照 |
obj\リリース\main.o:main.cpp|| 「通信用 vtable」への未定義参照 |
obj\リリース\main.o:main.cpp|| 「通信用 vtable」への未定義参照 |
obj\リリース\main.o:main.cpp|| `vtable for Communicate' への未定義の参照が続きます |
||=== ビルドが終了しました: 6 つのエラー、0 の警告 ===|
code:: blocks フォーラムの解決策を探していて、Qt プラグインをインストールする必要があることを知りました。
それで、QtWorkbench 0.6.0 alpha -> qt plugin をインストールしましたが、何も変わっていません。
どんな提案でも大歓迎です。