OS : windows xp SP2 , compiler : Code::Blocks ver. 10.05 , Qt 4.6
I recently started to learn Qt. At first all went well with simple tut examples. I soon came across an example that can not compile and and realized that something is wrong.
Here is the code :
#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();
}
When I try to open it, I get this message:
obj\Release\main.o:main.cpp|| undefined reference to `vtable for Communicate'|
obj\Release\main.o:main.cpp|| undefined reference to `vtable for Communicate'|
obj\Release\main.o:main.cpp|| undefined reference to `vtable for Communicate'|
obj\Release\main.o:main.cpp|| undefined reference to `vtable for Communicate'|
obj\Release\main.o:main.cpp|| undefined reference to `vtable for Communicate'|
obj\Release\main.o:main.cpp|| more undefined references to `vtable for Communicate' follow|
||=== Build finished: 6 errors, 0 warnings ===|
I was looking for a solution to the code:: blocks forum and learned that there should be Qt plugin installed.
So , I install QtWorkbench 0.6.0 alpha -> qt plugin but nothing has changed.
Any suggestion is welcome.