Results 1 to 6 of 6

Thread: How to change QStackedWidget index from Qdialog

  1. #1
    Join Date
    Feb 2013
    Location
    Banzart
    Posts
    54
    Thanks
    17
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default 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??


    Added after 4 minutes:


    I have to mention that i found this code
    Qt Code:
    1. //your dialog
    2. //the constructor
    3. YourDialog::YourDialog()
    4. {
    5. connect(ur_ok_btn, SIGNAL(clicked()), SLOT(accept ()));
    6. }
    7.  
    8. //access to line edit value
    9. QString YourDialog::getUserEnteredValue(){return ur_line_edit->text();}
    10.  
    11.  
    12. //your main window
    13. YourDialog dlg;
    14. if( dlg.exec() == QDialog::Accepted ){
    15. int i = dlg.getUserEnteredValue().toInt();
    16. ur_stacked_widget->setCurrentIndex(i);
    17. }
    To copy to clipboard, switch view to plain text mode 
    But it didn't helped me too much because i get mainly this error
    error: cannot call constructor 'YourDialog::YourDialog ' directly [-fpermissive]
    Last edited by sliverTwist; 19th March 2013 at 12:26.
    Sliver_Twist

  2. #2
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to change QStackedWidget index from Qdialog

    Try this, if this will help you
    Qt Code:
    1. //your dialog
    2. //the constructor
    3. YourDialog::YourDialog()
    4. {
    5. connect(ur_ok_btn, SIGNAL(clicked()), this, SLOT(accept ()));
    6. }
    7.  
    8. //access to line edit value
    9. QString YourDialog::getUserEnteredValue(){return ur_line_edit->text();}
    10.  
    11.  
    12. //your main window
    13. YourDialog *dlg = new YourDialog();
    14. if( dlg->exec()){
    15. qDebug() << " returned index number : " << dlg->getUserEnteredValue();
    16. int i = dlg->getUserEnteredValue().toInt();
    17. ur_stacked_widget->setCurrentIndex(i);
    18. }
    To copy to clipboard, switch view to plain text mode 

    check if getUserEnteredValue return a correct index number.

    CHEERS

  3. #3
    Join Date
    Feb 2013
    Location
    Banzart
    Posts
    54
    Thanks
    17
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to change QStackedWidget index from Qdialog

    Sorry sir that didn't helped me too much
    I have did this

    Qt Code:
    1. //My dialog
    2. Logindialog::Logindialog(QWidget *parent) :
    3. QDialog(parent),
    4. ui(new Ui::Logindialog)
    5. {
    6. ui->setupUi(this);
    7. connect(ui->configurePushButton,SIGNAL(clicked()), this, SLOT(accept ()));
    8. }
    To copy to clipboard, switch view to plain text mode 

    I have an action on the button that closes the dialog if clicked

    Qt Code:
    1. void Logindialog::on_configurePushButton_clicked()
    2. {
    3. close();
    4. }
    To copy to clipboard, switch view to plain text mode 

    and this is the creation of the Dialog
    Qt Code:
    1. Logindialog nLD;
    2. nLD.setModal(true);
    3. nLD.setWindowFlags( Qt::Dialog | Qt::Desktop
    4. |Qt::CustomizeWindowHint |Qt::CustomizeWindowHint
    5. | Qt::WindowTitleHint| Qt::WindowMinMaxButtonsHint |
    6. Qt::WindowMinimizeButtonHint );
    7. nLD.exec();
    8. if( nLD.exec() ){
    9. ui->stackedWidget->setCurrentIndex(0);
    10. }
    To copy to clipboard, switch view to plain text mode 
    Sliver_Twist

  4. #4
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to change QStackedWidget index from Qdialog

    closing a dialog will not catch by if condition.

    change
    Qt Code:
    1. void Logindialog::on_configurePushButton_clicked()
    2. {
    3. close();
    4. }
    To copy to clipboard, switch view to plain text mode 
    to
    Qt Code:
    1. void Logindialog::on_configurePushButton_clicked()
    2. {
    3. accept();
    4. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to change QStackedWidget index from Qdialog

    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.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to change QStackedWidget index from Qdialog

    Quote Originally Posted by sliverTwist View Post
    Sorry sir that didn't helped me too much
    I have did this

    Qt Code:
    1. //My dialog
    2. Logindialog::Logindialog(QWidget *parent) :
    3. QDialog(parent),
    4. ui(new Ui::Logindialog)
    5. {
    6. ui->setupUi(this);
    7. connect(ui->configurePushButton,SIGNAL(clicked()), this, SLOT(accept ()));
    8. }
    To copy to clipboard, switch view to plain text mode 

    I have an action on the button that closes the dialog if clicked

    Qt Code:
    1. void Logindialog::on_configurePushButton_clicked()
    2. {
    3. close();
    4. }
    To copy to clipboard, switch view to plain text mode 
    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,
    _

Similar Threads

  1. Replies: 2
    Last Post: 5th November 2012, 16:51
  2. Change QVBoxLayout index?
    By davidlamhauge in forum Qt Programming
    Replies: 2
    Last Post: 27th April 2012, 01:51
  3. Change QTableView's index number displayed
    By rex in forum Qt Programming
    Replies: 0
    Last Post: 6th April 2011, 16:30
  4. Replies: 4
    Last Post: 2nd March 2011, 10:03
  5. Replies: 0
    Last Post: 7th October 2010, 16:52

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.