gpt4 book ai didi

linux - 虚拟表未生成

转载 作者:太空宇宙 更新时间:2023-11-04 04:28:47 25 4
gpt4 key购买 nike

首先,非常感谢您抽出宝贵的时间查看我的问题。其次,我读过this我的类没有任何我忘记包含的虚拟方法。在描述我的问题后,我将回顾我尝试过的其他事情。

当我使用 gcc 版本 3.4.6 20060404 构建代码时,出现了对“SubcomponentTypeWidget 的 vtable” undefined reference 的错误。Visual Studio 2005 没有任何问题。我喜欢 Linux,但我目前的政治形势将它委托(delegate)给了经常遭受虐待的红发继子。希望通过我们的力量的结合,我可以弥补这一点。

我使用的是 Qt 版本 4.6.2。我在 Red Hat 4 上使用 gcc 3.4.6 20060404。

这是我的标题:

#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 文件以及小部件和 MeshAndGeometry make 和 .pro 文件 here作为文件。附件之一是 .ui 文件 here

我尝试过很多事情。

  1. 我确信这不是过时的对象文件问题。我从头开始构建了这个,但仍然存在问题。
  2. 我检查了所有大小写问题。我注意到在 Windows 上完成大部分工作然后将其迁移到 Linux 的问题之一是人们会在大小写方面犯错误,而 Windows 并不关心大小写。
  3. 我运行 nm -a -C SubcomponentTypeWidget.o 来查看是否存在必要的 vtable,但事实并非如此。然而,“缺失”的方法仍然存在。
  4. 创建虚拟析构函数不会强制为 SubcomponentTypeWidget 生成 vtable。
  5. 我尝试删除 SubcomponentTypeWidget 的大部分功能。这会导致删除方法的特定链接器错误消息,但不会删除对 vtable 消息的 undefined reference 。我已经从 SubcomponentTypeWidget 中删除了除构造函数之外的所有内容,在这种情况下,我仍然收到“对 vtable 的 undefined reference ”消息,但没有提及我们正在寻找的特定方法。
  6. 更改小部件和 MeshingAndGeometry 的链接顺序没有帮助。
  7. 我尝试过 gcc 版本 3.4.6 20060404 和 4.1.2 20080704。

帮助我,欧比旺·克诺比。你是我唯一的希望。

非常非常感谢大家,

-布莱恩·J·斯蒂纳尔-

最佳答案

检查了您的代码,错误很可能是由以下语句引起的:

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

通过将 SubcomponentTypeWidget 设为 Ui::SubcomponentTypeWidget 的子类,您有点破坏了 Qt 的结构。在这种情况下,您实际上是在使用自己来设置自己的 UI。再加上您使用多个类继承这一事实,您只是让编译器在运行时引用哪个虚拟方法感到困惑。

不要子类化 Ui::SubcomponentTypeWidget,只需将其设为 SubcomponentTypeWidget 中的私有(private)变量即可

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

在你的 init 函数中实现以下内容,你就可以开始了

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

关于linux - 虚拟表未生成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5747705/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com