QstackedWidget 段错误
各位大虾,请教个问题,我在Qt编译时出现段错误,我的代码:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QStackedWidget>
#include <QPushButton>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
QStackedWidget *stackedWidget;
QPushButton *pushButton;
QPushButton *pushButton_2;
QPushButton *pushButton_3;
QPushButton *pushButton_4;
QPushButton *pushButton_5;
private slots:
void changed_1();
void changed_2();
void changed_3();
void changed_4();
void changed_5();
};
#endif // MAINWINDOW_H
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
stackedWidget=new QStackedWidget;
connect(pushButton,SIGNAL(clicked()),this,SLOT(changed_1()));
connect(pushButton_2,SIGNAL(clicked()),this,SLOT(changed_2()));
connect(pushButton_3,SIGNAL(clicked()),this,SLOT(changed_3()));
connect(pushButton_4,SIGNAL(clicked()),this,SLOT(changed_4()));
connect(pushButton_5,SIGNAL(clicked()),this,SLOT(changed_5()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::changed_1()
{
stackedWidget->setCurrentIndex(0);
}
void MainWindow::changed_2()
{
stackedWidget->setCurrentIndex(1);
}
void MainWindow::changed_3()
{
stackedWidget->setCurrentIndex(2);
}
void MainWindow::changed_4()
{
stackedWidget->setCurrentIndex(3);
}
void MainWindow::changed_5()
{
stackedWidget->setCurrentIndex(4);
}
[解决办法]
那5个button没有new就用了,是空指针。
[解决办法]
pushButton 你new了吗 弱弱的问一句