Qt 应用程序框架中的分段错误 [英] Segmentation fault in Qt application framework
问题描述
这会产生分段错误,因为QColor colorMap[9]";.如果我删除 colorMap 分割错误就会消失.如果我把它放回去.它回来了.如果我做一个干净的所有然后构建所有,它就消失了.如果我增加它的数组大小,它就会回来.另一方面,如果我减少它,它不会回来.我厌倦了将此数组添加到另一个项目和
this generates a segmentation fault becuase of "QColor colorMap[9]";. If I remove colorMap the segmentation fault goes away. If I put it back. It comes back. If I do a clean all then build all, it goes away. If I increase its arraysize it comes back. On the other hand if I reduce it it doesnt come back. I tired adding this array to another project and
可能会发生什么.我真的很想知道.我已经删除了该课程中的所有其他内容.这个小部件的子类化用于提升 QMainWindow 中的小部件.
What could be happening. I am really curious to know. I have removed everything else in that class. This widget subclassed is used to promote a widget in a QMainWindow.
class LevelIndicator : public QWidget
{
public:
LevelIndicator(QWidget * parent);
void paintEvent(QPaintEvent * event );
float percent;
QColor colorMap[9];
int NUM_GRADS;
};
错误发生在 ui_mainwindow.h 中的以下行之一:
the error happens inside ui_mainwindow.h at one of these lines:
hpaFwdPwrLvl->setObjectName(QString::fromUtf8("hpaFwdPwrLvl"));
verticalLayout->addWidget(hpaFwdPwrLvl);
我知道我提供的不多,但我会提供该应用程序的链接.我想看看是否有人对此有一个快速的答案.
I know i am not providing much but I will give alink to the app. Im trying to see if anyone has a quick answer for this.
推荐答案
如果我先全部清理然后全部构建,它就会消失.
If I do a clean all then build all, it goes away.
这听起来好像您的构建系统没有识别依赖项,并且对该类定义的更改不会触发定义更改时应该重新编译的内容的重新构建.
This makes it sound as though your build system isn't recognizing a dependency and that a change to that class definition isn't triggering a rebuild of something that should be recompiled when the definition changes.
确保class LevelIndicator
定义在一个地方(通常是一个头文件,任何需要使用LevelIndicator
对象的模块都会包含该头文件).还要确保 LevelIndicator
对象的任何全局/静态实例都遵循一个定义规则.
Make sure class LevelIndicator
is defined in exactly one place (generally that would be a header file that gets included by whatever modules need to use a LevelIndicator
object). Also make sure that any global/static instances of LevelIndicator
objects are following the one definition rule.
这篇关于Qt 应用程序框架中的分段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!