Hi!

When I try to call QComboBox::addItem from another function in my class than the constructor, my application crashes.
I've made a short application to reproduce the crash, here's the code (.zip included for those who want).

ComboBoxCrash.pro
Qt Code:
  1. HEADERS += GUI.h
  2. SOURCES += GUI.cpp \
  3. main.cpp
To copy to clipboard, switch view to plain text mode 

main.cpp
Qt Code:
  1. #include <QtCore/QCoreApplication>
  2. #include <QtGui>
  3. #include "GUI.h"
  4.  
  5.  
  6. int main(int argc, char *argv[]){
  7. QApplication a(argc, argv);
  8.  
  9. ComboBoxCrash *MainWindow = new ComboBoxCrash;
  10. MainWindow->show();
  11. return a.exec();
  12. }
To copy to clipboard, switch view to plain text mode 

GUI.h
Qt Code:
  1. #ifndef GUI_H
  2. #define GUI_H
  3.  
  4. #include <QWidget>
  5.  
  6. class QComboBox;
  7.  
  8. class ComboBoxCrash : public QWidget{
  9. Q_OBJECT
  10.  
  11. public:
  12. ComboBoxCrash(QWidget *parent=0);
  13. public slots:
  14. void function();
  15. private:
  16. QComboBox *comboBox;
  17. QPushButton *crashButton;
  18. };
  19.  
  20. #endif // GUI_H
To copy to clipboard, switch view to plain text mode 

GUI.cpp
Qt Code:
  1. #include <QtGui>
  2. #include "GUI.h"
  3.  
  4. ComboBoxCrash::ComboBoxCrash(QWidget *parent) : QWidget(parent){
  5.  
  6. QComboBox *comboBox = new QComboBox;
  7. QPushButton *crashButton = new QPushButton("Crash");
  8.  
  9. QGridLayout *mainLayout = new QGridLayout;
  10. mainLayout->addWidget(comboBox,0,0);
  11. mainLayout->addWidget(crashButton,0,1);
  12. setLayout(mainLayout);
  13. setWindowTitle("ComboBox Crash");
  14.  
  15. comboBox->addItem("Item1");
  16. comboBox->addItem("Item2");
  17. comboBox->addItem("Item3");
  18.  
  19. connect(crashButton, SIGNAL(clicked()), this, SLOT(function()));
  20. }
  21.  
  22. void ComboBoxCrash::function(){
  23. comboBox->addItem("Item4");
  24. }
To copy to clipboard, switch view to plain text mode 

When the function which calls addItem is called, the application crashes.
I'm using Qt 4.5.2 and Qt Creator 1.2.0 under Windows XP SP2.

If anyone know why this happens, or even better, have a solution, I would be very happy.

Thanks in advance