2014-01-22 8 views
0

를 사용하는 경우 내가 Qt를 내 응용 프로그램에 문제가, 나는 QMainWindow를 사용하고 난 setupUi에서 구현 충돌 다른 위젯의 목표를 위해했던 것처럼 최대 2 QComboBox을 설정하려고 :QMainWindow 충돌 QComboBox

의 내 클래스 MainWindow를, 그것은 완벽하게 작동하고 내가 2 콤보 상자를 추가 할 때까지 표시했다.

MainWindow::MainWindow(Map *inMap, int dim1, int dim2) 
{ 
    _ui->setupUi(this); 
    _boxDim1 = new QComboBox(); 
    _boxDim2 = new QComboBox(); 
    _canvas = new Canvas(inMap, dim1, dim2); 
    _bouton = new QPushButton("Test !"); 
    _bouton->setToolTip("Bouton a push"); 
    _bouton->setCursor(Qt::PointingHandCursor); 
    connect(_bouton, SIGNAL(clicked()), this, SLOT(boutonClicked())); 
    QWidget *q = new QWidget(); 
    setCentralWidget(q); 
    QGridLayout *mainLayout = new QGridLayout(); 
    mainLayout->addWidget(_canvas, 1, 0, 1, 1); 
    mainLayout->addWidget(_bouton, 2, 0, 1, 1); 
    q->setLayout(mainLayout); 
} 

DDD에서 디버깅 후에는 segfault의 정확한 지점은 다음과 같습니다 :

_ui->setupUi(this); 

class MainWindow : public QMainWindow 
{ 
    Q_OBJECT 

    public: 
     explicit MainWindow(QWidget *parent = 0); 
     MainWindow(Map *inMap, int dim1, int dim2); 
     ~MainWindow(); 

    public slots: 
     void boutonClicked(); 

    private: 
     Ui::MainWindow *_ui; 
     QPushButton *_bouton; 
     Canvas *_canvas; 
     QComboBox *_boxDim1; 
     QComboBox *_boxDim2; 
}; 

콤보 상자를 추가 한 후, 프로그램은 제조업체의 성능에 충돌 이 함수 내 :

void setupUi(QMainWindow *MainWindow) 
{ 
    if (MainWindow->objetName().isEmpty()) 
     MainWindow->setObjectName(QString::fromUtf8("MainWindow")); 
    MainWindow->resize(800, 600); 
    centralwidget = new QWidget(MainWindow) /// Segfault ici. 
나는 또한 이후 문제를 완벽하게 그들의 부분에 대한 QPushButton을하고 캔버스의 생성을 수행 어디 파악하지 않는 것을 고백해야3210

.

답변

1

_ui 귀하의 변수는 충돌 이유입니다, 초기화되지 않았습니다. MainWindowQObject 두 번째 생성자에서 부모와 같은 매개 변수를 사용-이 드레스도, 그것으로 좋은 ... _ui = new Ui::MainWindow(); : 당신은 뭔가를해야합니다. 또는 단지 첫 번째를 사용하고 당신이 필요로하는 추가 매개 변수를 추가합니다.

+0

그것은 실제로하지 초기화 _ui했다. 나 한테 무슨 를 놀라게하는 것은이 프로젝트가 정리되지 않았기 때문에 대부분의 가능성이 초기화없이 거기까지 일 것입니다. – Woute