Re: How to change QStackedWidget index from Qdialog
My application have an "actionhelp" in the menu bar which when clicked opens up a QDialog that contains an ok button and some text in a label.
At the other side in the mainwindow i have a QStackedWidget.
So my question is how to change the index of the stackedwidget when i press that ok button in the QDialog?? :confused:
Added after 4 minutes:
I have to mention that i found this code
Code:
//your dialog
//the constructor
YourDialog::YourDialog()
{
connect(ur_ok_btn, SIGNAL(clicked()), SLOT(accept ()));
}
//access to line edit value
QString YourDialog
::getUserEnteredValue(){return ur_line_edit
->text
();
}
//your main window
YourDialog dlg;
if( dlg.
exec() == QDialog::Accepted ){ int i = dlg.getUserEnteredValue().toInt();
ur_stacked_widget->setCurrentIndex(i);
}
But it didn't helped me too much because i get mainly this error
Quote:
error: cannot call constructor 'YourDialog::YourDialog ' directly [-fpermissive]
Re: How to change QStackedWidget index from Qdialog
Try this, if this will help you
Code:
//your dialog
//the constructor
YourDialog::YourDialog()
{
connect(ur_ok_btn, SIGNAL(clicked()), this, SLOT(accept ()));
}
//access to line edit value
QString YourDialog
::getUserEnteredValue(){return ur_line_edit
->text
();
}
//your main window
YourDialog *dlg = new YourDialog();
if( dlg->exec()){
qDebug() << " returned index number : " << dlg->getUserEnteredValue();
int i = dlg->getUserEnteredValue().toInt();
ur_stacked_widget->setCurrentIndex(i);
}
check if getUserEnteredValue return a correct index number.
CHEERS
Re: How to change QStackedWidget index from Qdialog
Sorry sir that didn't helped me too much
I have did this
Code:
//My dialog
Logindialog
::Logindialog(QWidget *parent
) : ui(new Ui::Logindialog)
{
ui->setupUi(this);
connect(ui->configurePushButton,SIGNAL(clicked()), this, SLOT(accept ()));
}
I have an action on the button that closes the dialog if clicked
Code:
void Logindialog::on_configurePushButton_clicked()
{
close();
}
and this is the creation of the Dialog
Code:
Logindialog nLD;
nLD.setModal(true);
nLD.setWindowFlags( Qt::Dialog | Qt::Desktop
|Qt::CustomizeWindowHint |Qt::CustomizeWindowHint
| Qt::WindowTitleHint| Qt::WindowMinMaxButtonsHint |
Qt::WindowMinimizeButtonHint );
nLD.exec();
if( nLD.exec() ){
ui->stackedWidget->setCurrentIndex(0);
}
Re: How to change QStackedWidget index from Qdialog
closing a dialog will not catch by if condition.
change
Code:
void Logindialog::on_configurePushButton_clicked()
{
close();
}
to
Code:
void Logindialog::on_configurePushButton_clicked()
{
accept();
}
Re: How to change QStackedWidget index from Qdialog
Quote:
But it didn't helped me too much because i get mainly this error
error: cannot call constructor 'YourDialog::YourDialog ' directly [-fpermissive]
Maybe you have solved your problem by now. Karankumar1609's suggestion in the first reply is not correct - if you can't construct a YourDialog instance on the stack, you won't be able to construct it with new() either.
What does the declaration of the YourDialog look like in YourDialog.h? Is YourDialog derived from QDialog? Does it declare Q_OBJECT? Does the constructor for YourDialog have a QWidget * argument (for the parent)? Your cpp code is not correct if that is how you actually implemented the constructor for your dialog class.
Re: How to change QStackedWidget index from Qdialog
Quote:
Originally Posted by
sliverTwist
Sorry sir that didn't helped me too much
I have did this
Code:
//My dialog
Logindialog
::Logindialog(QWidget *parent
) : ui(new Ui::Logindialog)
{
ui->setupUi(this);
connect(ui->configurePushButton,SIGNAL(clicked()), this, SLOT(accept ()));
}
I have an action on the button that closes the dialog if clicked
Code:
void Logindialog::on_configurePushButton_clicked()
{
close();
}
You don't need that you already have the button connected to the accept() slot.
If you need to do anything additional to accepting (this closing the dialog and making exec() return QDIalog::Accepted), simply overwrite accept() (it is a virtual method for exactly that reason)
Cheers,
_