PDA

View Full Version : QComboBox problem



SteveH
2nd March 2009, 20:04
Hi,
I've a recurring problem with QComboBox's causing a program crash.
I am using QCreator 0.9.2 RC1 and am building a QMainWindow which then calls a QIODevice class which then calls a QDialog class, the QComboBox's are in the QDialog class. If I use a QComboBox access like say ComboBox->setCurrentIndex(2) anywhere but in the function where the QComboBox is created then the program will crash when it reaches that point.
I built a minimal test program of the above layout which always worked but as soon as I add lots of elements the program will always crash.
Does anyone have a handle as to where I'm going wrong ???
A sample of the program is listed below with virtualy everything stripped out but still able to crash everytime.

jpn
2nd March 2009, 20:31
This one assigns to a local variable, leaving the member variable uninitialized:

QComboBox *PortSel = new QComboBox() ;
This one assigns to the member variable:

PortSel = new QComboBox() ;

SteveH
2nd March 2009, 21:20
Thanks jpn !

It's blindingly obvious when you pointed it out (I'll give myself a slap now) and I know exactly where I did it (cut & paste from the header file) but I just couldn't see the wood for the trees !