C++ 如何从Qdialog更改QStackedWidget索引
我的应用程序在菜单栏中有一个“actionhelp”,单击它会打开一个QDialog,在主窗口的另一侧包含一个ok按钮,我有一个QStackedWidgetC++ 如何从Qdialog更改QStackedWidget索引,c++,qt4,qdialog,C++,Qt4,Qdialog,我的应用程序在菜单栏中有一个“actionhelp”,单击它会打开一个QDialog,在主窗口的另一侧包含一个ok按钮,我有一个QStackedWidget 所以我的问题是,当我按下QDialog中的ok按钮时,如何更改stackedwidget的索引???信号和插槽。将ok按钮的信号(或在关闭QDialog::Accepted后检查QDialog::Accepted时发出自己的信号)连接到一个插槽,该插槽将更改QStackedWidget中的索引 示例代码: 在主方法中创建并连接QAction
所以我的问题是,当我按下QDialog中的ok按钮时,如何更改stackedwidget的索引???信号和插槽。将ok按钮的信号(或在关闭QDialog::Accepted后检查QDialog::Accepted时发出自己的信号)连接到一个插槽,该插槽将更改QStackedWidget中的索引 示例代码: 在主方法中创建并连接QAction:
QAction *displayDialog = new QAction("Display Dialog", this);
connect(popup, SIGNAL(triggered()), this, SLOT(showDialog()));
显示对话框:
void showDialog()
{
YourDialog *dialog = new YourDialog(this);
int return_code = dialog.exec();
if (return_code == QDialog::Accepted)
{
int index = someValue;
qStackedWidget.setCurrentIndex(index);
}
}
假设对话框上有行编辑,并且希望根据行编辑值(或旋转框)更改堆叠小部件的索引: 在其中创建对话类的实例:
//your main window
YourDialog dlg;
if( dlg.exec() == QDialog::Accepted ){
int i = dlg.getUserEnteredValue().toInt();
ur_stacked_widget->setCurrentIndex(i);
}
你的对话中有什么对你很重要的东西吗?像QLineEdit?不只是标签中的一些“文本”,也没有从QDialog发送到mainwindow的任何东西尝试给我这个结果:/home/sliver/Documents/Workspace/clinetCloud/mainwindow.cpp:34:错误:无法直接调用构造函数“Logindialog::Logindialog”[-fpermissive]也许您已经定义了构造函数私有。
//your main window
YourDialog dlg;
if( dlg.exec() == QDialog::Accepted ){
int i = dlg.getUserEnteredValue().toInt();
ur_stacked_widget->setCurrentIndex(i);
}