Results 1 to 3 of 3

Thread: How to access QStackedWidget widgets

  1. #1
    Join Date
    Apr 2015
    Posts
    28
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default How to access QStackedWidget widgets

    I have a QTreeWidget where the user adds a list of networking items to be scanned. Once the "scan" button is clicked it loops though the list and reads the configuration from each device. This is all stored in objects of the Device class that I've created (one for each device).

    To show the result, I've created a bunch of QTabWidgets that are stacked in a QStackedWidget. The problem I have is updating the widgets in the tabs once they are shown on screen. Right now I don't save the widgets anywhere (except on the stack) so I cannot access them later on. I can't figure out how to store the widgets in a nice way for easy access. Storing them in self won't work, multiple network devices will cause overwriting. Storing them in the Device objects caused a crash ("You can't create a QPaintedObject before a QApplication" or something like that).

    The only thing I can think of is creating a list in self and store the widgets there, and then try to identify widgets in the list somehow to find the right one, but there's got to be an easier way...? Is it possible to access them on the stack?

    Any thoughts on how to solve this is appreciated.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to access QStackedWidget widgets

    In QStackedWidget You have two methods QStackedWidget::widget(int) and QStackedWidget::currentWidget() to take a pointer to widget.

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

    Default Re: How to access QStackedWidget widgets

    except on the stack
    I hope you mean "on the QStackedWidget" and not on the memory stack. If you're putting QWidget instances on the stack, they'll vanish as soon as they go out of scope.

    You can always keep QWidget pointers in lists or vectors after they have been properly created and given a QWidget parent. To make sure you don't end up with dangling pointers, you can connect a slot to their QObject::destroyed() signal and use that to remove the sender from the collection of pointers.

    The "can't create..." error arises when you try to create QWidget instances before you have a QApplication object created. This could happen if you declare QWidgets (not QWidget pointers) as members of a class that is constructed before QApplication (or if pointers, you try to create the instances in the construction of the class containing them), if you declare QWidgets at global scope, if you try to build lists (or whatever) of QWidget, or any other number of ways that your code tries to create a QWidget prior to the QApplication being constructed.

Similar Threads

  1. Replies: 3
    Last Post: 25th July 2010, 19:15
  2. Access objects inside QStackedWidget widgets.
    By Trader in forum Qt Programming
    Replies: 0
    Last Post: 25th July 2010, 17:10
  3. how to access widgets values?
    By BalaQT in forum Qt Programming
    Replies: 4
    Last Post: 22nd August 2009, 12:06
  4. All widgets are visible in QStackedWidget
    By YuriyRusinov in forum Qt Programming
    Replies: 14
    Last Post: 22nd March 2007, 12:02
  5. Access widgets
    By Gayathri in forum Newbie
    Replies: 2
    Last Post: 17th November 2006, 14:37

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.