kenchan
6th December 2012, 13:17
i want to implement below function:
mainwindow have two widget(A is stackwidget and B is QFrame).
1. at first A is showed.
2. when click QAction action_B, A is hided, B is showed.
3. when click QAction action_A, A is showed, B is hided.
when debugger.
At first click action_A, can show A and hide B, but segmentation fault when i cllick action_B.
i delete this->setCentralWidget(A) or this->setCentralWidget(B) , no fault was happened.
if i want to implement function above what i said. how to program? please give me any advice. thank your for your help!
codes see as below:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
...............
this->setCentralWidget(A);
}
void MainWindow::init();
{
ui->action_A->setEnabled(true);
ui->action_B->setEnabled(false);
a->hide();
..........
this->setCentralWidget(B);
b->show();
}
void MainWindow::on_action_A_triggered()
{
b->hide();
a->show();
ui->action_A->setEnabled(false);
ui->action_B->setEnabled(true);
......
}
void MainWindow::on_action_B_triggered()
{
init();
}
TKS.
ken
mainwindow have two widget(A is stackwidget and B is QFrame).
1. at first A is showed.
2. when click QAction action_B, A is hided, B is showed.
3. when click QAction action_A, A is showed, B is hided.
when debugger.
At first click action_A, can show A and hide B, but segmentation fault when i cllick action_B.
i delete this->setCentralWidget(A) or this->setCentralWidget(B) , no fault was happened.
if i want to implement function above what i said. how to program? please give me any advice. thank your for your help!
codes see as below:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
...............
this->setCentralWidget(A);
}
void MainWindow::init();
{
ui->action_A->setEnabled(true);
ui->action_B->setEnabled(false);
a->hide();
..........
this->setCentralWidget(B);
b->show();
}
void MainWindow::on_action_A_triggered()
{
b->hide();
a->show();
ui->action_A->setEnabled(false);
ui->action_B->setEnabled(true);
......
}
void MainWindow::on_action_B_triggered()
{
init();
}
TKS.
ken