引用第4楼jdwx于2013-05-27 11:18发表的 :
在按钮的槽里: stackedWidget->setCurrentIndex(int index);第一个widget是0

我这样做了,信号也触发了,但我的widget一个都没有show出来。什么原因呢。
这是我的代码
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
stack = new QStackedWidget;
widget1 *u1 = new widget1;
widget2 *u2 = new widget2;
stack->addWidget(u1);
stack->addWidget(u2);
connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(show1()));
connect(ui->pushButton_2,SIGNAL(clicked()),this,SLOT(show2()));
}
void MainWindow::show1()
{
QMessageBox::information(this,"info","show1","OK");
stack->setCurrentIndex(0);
}