Segmentation fault in Qt application framework

别说谁变了你拦得住时间么 提交于 2019-12-31 07:24:10

问题


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

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;  
};  

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.


回答1:


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.

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.




回答2:


Firstly it might not be QColor, that may simply be changing the memory layout enough that a buffer overrun somewhere else triggers a segfault - try a different size QColor ..[1] for example.

Can QColor be used as an array like this, does it have the correct default ctor?



来源:https://stackoverflow.com/questions/2933067/segmentation-fault-in-qt-application-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!