PDA

View Full Version : Program crashes if i want to clear() a combobox!?



Terreox
7th February 2012, 15:11
Hi there
i dont know how to solve one problem.
I designed a controlpanel for my program with QtDesigner and added controlpanel.cpp and controlpanel.h to be able to add more functionality.
Now i have a problem:
On the GUI there are several Comboboxes. If a new ControlPanel is created all comboboxes should be cleared and initialized with some items.

Controlpanel.h

#ifndef CONTROLPANEL_H
#define CONTROLPANEL_H
#include <QMainWindow>
#include "ui_controlpanel.h"

class ControlPanel : public QMainWindow, public Ui::ControlPanel
{
Q_OBJECT

public:
ControlPanel();

private:
void initStatusVectors();
void setComboBoxes();

QVector<QString> statusVec;
};


#endif // CONTROLPANEL_H


And this is Controlpanel.cpp

#include <QMainWindow>
#include <QtGui>
#include "controlpanel.h"

//INITIALIZE STATUS-VECTOR
void ControlPanel::initStatusVectors()
{
statusVec.push_back("1");
statusVec.push_back("2");
statusVec.push_back("3");
statusVec.push_back("4");
statusVec.push_back("5");
statusVec.push_back("6");
statusVec.push_back("7");
statusVec.push_back("8");
statusVec.push_back("9");
}

void ControlPanel::setComboBoxes()
{
this->combStatus1->clear();
}

ControlPanel::ControlPanel(QWidget *parent)
: QMainWindow(parent)
{
//INITIALIZE STATUS-VECTOR
initStatusVectors();

setComboBoxes();

setupUi(this);
}



If i leave out setComboBoxes() everything works fine i guess. Nothing bad happens.
But if i call setComboBoxes(); the program crashes before showing the GUI. So i press CTRL+R and then the crash message of windows appears
"ControlPanel has crashed and so on..."

I really dont know whats the problem is? Can anyone help me?

Greetz

FelixB
7th February 2012, 15:40
your program crashes because "combStatus1" is NULL. you have to call "setupUi(this)" to initialize your ui.

stampede
7th February 2012, 15:41
Where do you initialize this->combStatus1 ?
edit: you have to initialize ui first, then use it, not the other way around

Terreox
7th February 2012, 20:19
Oh ok thanks :) Yes it makes sense to initialize the ui first^^