Results 1 to 4 of 4

Thread: Silly question on QStacked Widget

  1. #1
    Join Date
    Sep 2017
    Posts
    12
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Silly question on QStacked Widget

    So I have the following code:

    Qt Code:
    1. void Classy::on_checkBox_pressed()
    2. {
    3. qDebug() << "Box Pressed";
    4. layout->addWidget(stackedWidget);
    5. stackedWidget->setCurrentWidget(sickWidget);
    6. stackedWidget->setLayout(layout);
    7. stackedWidget->show();
    8. }
    To copy to clipboard, switch view to plain text mode 

    Layout is a QVBoxLayout that I defined in public under classy.
    stackedWidget is a stackedWidget that I have as as stacked Widget in my ui.
    sickWidget is a "page" (QWidget) that has more objects underneath it.

    i looked at all kinds of documentation for this including this thread: http://www.qtcentre.org/threads/6878...qstackedwidget

    (I have w.show(); inside of main.cpp) However whenever I select the checkbox in my program it crashes and I don't understand what I'm doing wrong as I'm trying my best to follow the example in the Qt documentation under QStackedWidget. Can anyone help me?

    Thank you again to everyone.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Silly question on QStacked Widget

    Qt Code:
    1. void Classy::on_checkBox_pressed()
    2. {
    3. qDebug() << "Box Pressed";
    4. layout->addWidget(stackedWidget);
    5. stackedWidget->setCurrentWidget(sickWidget);
    6. //stackedWidget->setLayout(layout); // This should not be done, layout of stackedWidget is managed internally by QStackedWidget.
    7. //stackedWidget->show(); // Need not show this directly, just show the top level widget which contains the stackedWidget.
    8. }
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Sep 2017
    Posts
    12
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Silly question on QStacked Widget

    I attempted to delete those lines and I also intizalized the variables i mentioned before as well however now its stating that stackedWidget and nfsWidget are uninitialized.
    I am attempting to find a way to initialize them so that they can be seen as Widgets that I have built inside of the ui. I've tried different enumerations of this and have gotten no where.
    Obviously when attempt to run this it crashes due to lack of intilization. Thoughts?

    Qt Code:
    1. void Classy::on_checkBox_pressed()
    2. {
    3. QVBoxLayout *layout;
    4. QStackedWidget *stackedWidget;
    5. QWidget *nfsWidget;
    6. layout.addWidget(stackedWidget);
    7. stackedWidget.setCurrentWidget(nfsWidget);
    8. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Silly question on QStacked Widget

    Quote Originally Posted by seerofsorrow View Post
    ... Thoughts?
    You need to work on your C++ skills.

    See if this helps you understand your problem
    - Make layout, stackedWidget, sickWidget and nfsWidget as member variable of Classy.
    - Initialise layout, stackedWidget, sickWidget and nfsWidget in Classy constructor
    - layout.addWidget(stackedWidget); // Move this to Classy constructor
    - then try this code

    Qt Code:
    1. void Classy::on_checkBox1_pressed()
    2. {
    3. stackedWidget->setCurrentWidget(sickWidget);
    4. }
    5.  
    6. void Classy::on_checkBox2_pressed()
    7. {
    8. stackedWidget->setCurrentWidget(nfsWidget);
    9. }
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. Question which I don't feel like is quite as silly.
    By seerofsorrow in forum Newbie
    Replies: 5
    Last Post: 3rd October 2017, 23:41
  2. Silly Question/A very silly question
    By seerofsorrow in forum Newbie
    Replies: 1
    Last Post: 21st September 2017, 23:24
  3. signal acrorss different QStacked Widgets
    By hass26 in forum Qt Programming
    Replies: 7
    Last Post: 7th March 2015, 09:52
  4. Simple and silly question about QWidget
    By dima in forum Qt Programming
    Replies: 3
    Last Post: 2nd December 2010, 09:14
  5. QStacked Widget.
    By csvivek in forum Qt Tools
    Replies: 1
    Last Post: 21st May 2008, 13:57

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.