0

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.

2 Answers 2

3

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.

1
  • You're correct. qmake doesn't always correctly propagate changes in headers through the rest of the build system. Commented May 29, 2010 at 0:28
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?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.