2011-04-21 46 views
0

首先,非常感謝您花時間看我的問題。其次,我已閱讀this,我的班級沒有任何虛擬方法,我忘記了包括在內。在描述我的問題後,我會嘗試嘗試其他的東西。VTable Not Generated

我得到一個未定義的引用'vtable for SubcomponentTypeWidget'錯誤,當我使用gcc版本3.4.6 20060404構建我的代碼時。Visual Studio 2005沒有問題。我喜歡Linux,但是我目前的政治形勢已經將它委託給經常遭受虐待的紅頭髮的小孩。希望通過我們的力量加起來,我可以解決這個問題。

我正在使用Qt版本4.6.2。我用gcc 3.4.6 20060404紅帽4.

這是我的頭:

#ifndef SubcomponentTypeWidget_h 
#define SubcomponentTypeWidget_h 

#include <vector> 
#include "ui_SubcomponentTypeWidget.h" 
#include "Subcomponent.h" 

class SubcomponentTypeWidget : public QWidget, public Ui::SubcomponentTypeWidget 
{ 
    Q_OBJECT 

    Q_PROPERTY(QString title READ title WRITE setTitle) 

public: 
    SubcomponentTypeWidget(QWidget* parent, 
     Models::Subcomponent::SubcomponentType subcomponentType = Models::Subcomponent::kSolid) 
    : QWidget(parent), 
    m_subcomponentType(subcomponentType), 
     m_subcomponentTypeButtonGroup(new QButtonGroup(this)) 
    { 
     this->initialize(); 
    } 

    Models::Subcomponent::SubcomponentType subcomponentType() const { return m_subcomponentType; } 

    void setSubcomponentType(Models::Subcomponent::SubcomponentType type); 
    void setNonCompatibleTypes(const std::vector<Models::Subcomponent::SubcomponentType>& types); 

    QString title() const { return m_subcomponentGroupBox->title(); } 
    void setTitle(const QString &title) { m_subcomponentGroupBox->setTitle(title); } 

signals: 
    void subcomponentTypeChanged(); 

protected slots: 
    void handleSubcomponentTypeChoice(int subcomponentTypeChoiceId); 

protected: 
    void initialize(); 
    Models::Subcomponent::SubcomponentType m_subcomponentType; 
    QButtonGroup* m_subcomponentTypeButtonGroup; 
}; 

#endif // SubcomponentTypeWidget_h 

的實施是在這裏:

我收到
#include "SubcomponentTypeWidget.h" 

void SubcomponentTypeWidget::setSubcomponentType(Models::Subcomponent::SubcomponentType type) 
{ 
    if (type != m_subcomponentType) 
    { 
     m_subcomponentType = type; 
     emit subcomponentTypeChanged(); 
    } 
} 

void SubcomponentTypeWidget::setNonCompatibleTypes(const std::vector<Models::Subcomponent::SubcomponentType>& types) 
{ 
    m_subcomponentTypeButtonGroup->button(static_cast<int>(Models::Subcomponent::kSolid) + 1)->setEnabled(true); 
    m_subcomponentTypeButtonGroup->button(static_cast<int>(Models::Subcomponent::kComplement) + 1)->setEnabled(true); 
    m_subcomponentTypeButtonGroup->button(static_cast<int>(Models::Subcomponent::kHole) + 1)->setEnabled(true); 

    for (std::vector<Models::Subcomponent::SubcomponentType>::const_iterator it = types.begin(); it != types.end(); ++it) 
    { 
     m_subcomponentTypeButtonGroup->button(static_cast<int>(*it) + 1)->setEnabled(false); 
     if (*it == m_subcomponentType) 
      m_subcomponentTypeButtonGroup->button(static_cast<int>(Models::Subcomponent::kSolid) + 1)->setChecked(true); 
    } 
} 

void SubcomponentTypeWidget::handleSubcomponentTypeChoice(int subcomponentTypeChoiceId) 
{ 
    if (static_cast<Models::Subcomponent::SubcomponentType>(subcomponentTypeChoiceId - 1) != m_subcomponentType) 
    { 
     m_subcomponentType = static_cast<Models::Subcomponent::SubcomponentType>(subcomponentTypeChoiceId - 1); 
     emit subcomponentTypeChanged(); 
    } 
} 

void SubcomponentTypeWidget::initialize() 
{ 
    this->setupUi(this); 

    m_subcomponentTypeButtonGroup->addButton(m_solidRadioButton, static_cast<int>(Models::Subcomponent::kSolid) + 1); 
    m_subcomponentTypeButtonGroup->addButton(m_complementRadioButton, static_cast<int>(Models::Subcomponent::kComplement) + 1); 
    m_subcomponentTypeButtonGroup->addButton(m_holeRadioButton, static_cast<int>(Models::Subcomponent::kHole) + 1); 

    m_subcomponentTypeButtonGroup->button(static_cast<int>(m_subcomponentType) + 1)->setChecked(true); 

    connect(m_subcomponentTypeButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(handleSubcomponentTypeChoice(int))); 
} 

實際的錯誤信息是:

../lib/libMeshAndGeometry.a(AddAdvancedDialog.o)(.gnu.linkonce.t._ZN20Ui_AddAdvancedDialog7setupUiEP7QDialog+0x955): In function `Ui_AddAdvancedDialog::setupUi(QDialog*)': 
: undefined reference to `vtable for SubcomponentTypeWidget' 
../lib/libMeshAndGeometry.a(AddAdvancedDialog.o)(.gnu.linkonce.t._ZN20Ui_AddAdvancedDialog7setupUiEP7QDialog+0x960): In function `Ui_AddAdvancedDialog::setupUi(QDialog*)': 
: undefined reference to `vtable for SubcomponentTypeWidget' 
../lib/libMeshAndGeometry.a(AddAdvancedDialog.o)(.gnu.linkonce.t._ZN20Ui_AddAdvancedDialog7setupUiEP7QDialog+0x99b): In function `Ui_AddAdvancedDialog::setupUi(QDialog*)': 
: undefined reference to `SubcomponentTypeWidget::initialize()' 
../lib/libMeshAndGeometry.a(AddBoxDialog.o)(.gnu.linkonce.t._ZN15Ui_AddBoxDialog7setupUiEP7QDialog+0xfe8): In function `Ui_AddBoxDialog::setupUi(QDialog*)': 
: undefined reference to `vtable for SubcomponentTypeWidget' 
../lib/libMeshAndGeometry.a(AddBoxDialog.o)(.gnu.linkonce.t._ZN15Ui_AddBoxDialog7setupUiEP7QDialog+0xff3): In function `Ui_AddBoxDialog::setupUi(QDialog*)': 
: undefined reference to `vtable for SubcomponentTypeWidget' 
../lib/libMeshAndGeometry.a(AddBoxDialog.o)(.gnu.linkonce.t._ZN15Ui_AddBoxDialog7setupUiEP7QDialog+0x102e): In function `Ui_AddBoxDialog::setupUi(QDialog*)': 
: undefined reference to `SubcomponentTypeWidget::initialize()' 
../lib/libMeshAndGeometry.a(AddConeDialog.o)(.gnu.linkonce.t._ZN16Ui_AddConeDialog7setupUiEP7QDialog+0x7ef): In function `Ui_AddConeDialog::setupUi(QDialog*)': 
: undefined reference to `vtable for SubcomponentTypeWidget' 
../lib/libMeshAndGeometry.a(AddConeDialog.o)(.gnu.linkonce.t._ZN16Ui_AddConeDialog7setupUiEP7QDialog+0x7fa): In function `Ui_AddConeDialog::setupUi(QDialog*)': 
: undefined reference to `vtable for SubcomponentTypeWidget' 
../lib/libMeshAndGeometry.a(AddConeDialog.o)(.gnu.linkonce.t._ZN16Ui_AddConeDialog7setupUiEP7QDialog+0x835): In function `Ui_AddConeDialog::setupUi(QDialog*)': 
: undefined reference to `SubcomponentTypeWidget::initialize()' 
../lib/libMeshAndGeometry.a(AddCylinderDialog.o)(.gnu.linkonce.t._ZN20Ui_AddCylinderDialog7setupUiEP7QDialog+0x9c4): In function `Ui_AddCylinderDialog::setupUi(QDialog*)': 
: undefined reference to `vtable for SubcomponentTypeWidget' 
../lib/libMeshAndGeometry.a(AddCylinderDialog.o)(.gnu.linkonce.t._ZN20Ui_AddCylinderDialog7setupUiEP7QDialog+0x9cf): In function `Ui_AddCylinderDialog::setupUi(QDialog*)': 
: undefined reference to `vtable for SubcomponentTypeWidget' 
../lib/libMeshAndGeometry.a(AddCylinderDialog.o)(.gnu.linkonce.t._ZN20Ui_AddCylinderDialog7setupUiEP7QDialog+0xa0a): In function `Ui_AddCylinderDialog::setupUi(QDialog*)': 

我所有的makefile文件都是使用qmake從我的.pro文件生成的。主make文件,主.pro文件,Widgets和MeshAndGeometry make和.pro文件附加爲here作爲歸檔文件。其中一個.ui文件附於here

我試過了很多東西。

  1. 我確定這不是一個陳舊的對象文件問題。我從頭開始建立這個,我仍然有這個問題。
  2. 我檢查了我所有的大小寫問題。我注意到,在Windows上進行大部分操作並將其轉移到Linux時,其中一個問題是人們在大寫時出錯,而Windows並不關心大小寫。
  3. 我運行了nm -a -C SubcomponentTypeWidget.o以查看是否有必要的vtable,但事實並非如此。然而,「缺失」的方法在那裏。
  4. 創建虛擬析構函數不會強制SubcomponentTypeWidget的vtable生成。
  5. 我已經嘗試刪除大塊SubcomponentTypeWidget的功能。這會導致刪除方法的特定鏈接器錯誤消息,但它不會刪除對vtable消息的未定義引用。我從SubcomponentTypeWidget除了構造函數之外刪除了所有內容,在這種情況下,我仍然收到「對vtable的未定義引用」消息,但沒有提及我們正在尋找的特定方法。
  6. 更改鏈接的小部件和MeshingAndGeometry的順序無濟於事。
  7. 我已經試過版本的GCC 3.4.6 20060404和4.1.2 20080704.

幫幫我,歐比旺·克諾比。你是我唯一的希望。

非常感謝大家,非常非常,

-Brian J.Stinar-

+1

嘗試在'SubcomponentTypeWidget.h'標頭中包含'QObject'類。 – SIFE 2011-04-21 17:51:11

+0

它就在那裏,高於Q_PROPERTY和低於類SubcomponentTypeWidget:public QWidget,public Ui :: SubcomponentTypeWidget { – 2011-04-21 18:00:05

+1

@Brian我說頭不是宏。 – SIFE 2011-04-21 18:01:57

回答

0

我的問題與解決方案點數六。我其實沒有正確改變這個順序。我正在改變INCPATH中的順序,而不是LIBS中的順序。

在我的master.pro文件中添加MeshAndGeometry.depends = widgets行後,運行qmake並運行make,此問題就消失了。

非常感謝大家的評論和幫助。

-Brian J. Stinar-

0

通過你的代碼去,錯誤很可能源於以下語句:

======================================================= 
void SubcomponentTypeWidget::initialize() 
{ 
    this->setupUi(this); 
    //rest of codes 
} 
======================================================= 

你是那種通過使SubcomponentTypeWidget UI的一個子類:: SubcomponentTypeWidget打破的Qt的結構。在這種情況下,您實際上正在使用自己來設置自己的用戶界面。再加上你使用多個類繼承的事實,你只是混淆了編譯器在運行時引用哪個虛擬方法。

相反子類的UI :: SubcomponentTypeWidget,只是讓一個私有變量在SubcomponentTypeWidget

//SubcomponentTypeWidget.h 
    private: 
     Ui::SubcomponentTypeWidge ui; 

實現你的初始化函數如下,你應該是好去

void SubcomponentTypeWidget::initialize() 
{ 
    ui.setupUi(this); 
    //rest of codes 
} 
+0

我將在我的新建重建完成後直接嘗試此操作。謝謝。 – 2011-04-21 19:09:49

+0

完成此操作後,我仍收到相同的錯誤消息。 非常奇怪的是nm -a -C SubcomponentTypeWidget.o在這兩個輸出上都是相同的。這根本沒有任何意義,如果我是一個Ui_SubcomponentTypeWidget而不是我包含Ui_SubcomponentTypeWidget,這些不應該是不同的嗎? – 2011-04-21 20:47:06