由 turtle1234 » 週三 5月 28, 2008 11:30 pm
大大你好以下是我相關的程式碼,我用了你說的方法
但是在放入hello.cpp時那一行程式碼都會有錯,
真是不知什麼原因,可以請大大指導一下嗎?
錯誤訊息是以下:
C:/Qt/mytest/hello.cpp: undefined reference to `vtable for edit1'
debug/hello.o(.text$_ZN5edit1C1Ev[edit1::edit1()]+0x2c):C:/Qt/mytest/hello.cpp:
undefined reference to `vtable for edit1'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\mytest.exe] Error 1
mingw32-make[1]: Leaving directory `C:/Qt/mytest'
mingw32-make: *** [debug] Error 2
以下是我的程式碼
//!!!!!!!!!!!!!hello.h!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
class edit1 : public QLineEdit
{
protected:
void mouseDoubleClickEvent(QMouseEvent* event);
};
class Hello : public QDialog
{
Q_OBJECT
public:
Hello(QWidget *parent = 0);
~Hello();
void setedit(QString str);
private:
QHBoxLayout *layout;
QPushButton *button;
QLineEdit *edit;
edit1 *edit2;
private slots:
void created();
};
//!!!!!!!!!!!!!!!!!!!!hello.cpp!!!!!!!!!!!!!!!!!!!!!!!!!!!
Hello::Hello(QWidget *parent)
: QDialog(parent)
{
layout = new QHBoxLayout;
button = new QPushButton("Pressed");
edit = new QLineEdit;
edit2=new edit1;<-------------這一行為什麼會錯呢?
layout->addWidget(button);
layout->addWidget(edit);
//layout->addWidget(edit2);
this->setLayout(layout);
connect(button, SIGNAL(clicked()), this, SLOT(created()));
}