Results 1 to 8 of 8

Thread: what happened to toolBars() in Qt4?

  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default what happened to toolBars() in Qt4?

    I need a function to return a List of all toolbars in the mainwindow. There used to be a toolBars() method in Qt3 that is gone now and I could'nt find an alternative. My current workaround is pretty ugly and I would like to know if there is a better way or a qt function that does this.

    Thanx in advance

    current workaround
    Qt Code:
    1. QList<QToolBar*> MainWindow::toolBars()
    2. {
    3. QList<QToolBar*> tbs;
    4. QToolBar *tb;
    5. foreach(QObject* o, children()) {
    6. tb = dynamic_cast<QToolBar*>(o);
    7. if (tb)
    8. tbs << tb;
    9. }
    10. return tbs;
    11. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: what happened to toolBars() in Qt4?

    It seems that function is gone. You can however replace your call to toolBars() with
    Qt Code:
    1. findChildren<QToolBar*>()
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: what happened to toolBars() in Qt4?

    A simple solution is to keep the list of toolbars filled while adding them to the main window.

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: what happened to toolBars() in Qt4?

    Thanks. The first solution seems more bulletproof since I might forget adding it to the list somehow and then I would unintentionally miss out on that Toolbar.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: what happened to toolBars() in Qt4?

    Depends what you value more - execution speed or one compilation less.

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: what happened to toolBars() in Qt4?

    Quote Originally Posted by wysota View Post
    Depends what you value more - execution speed or one compilation less.
    In this case, none of them. easier maintainability is the driving factor . The purpose of the code is actually to dynamically query all toolbars for their state (visible/hidden) and save them using QSettings and their objectName and restore their state on startup again. So this is only called twice during the lifetime of the program. What bears the most value to me is painless maintainance. Of course manually adding the Toolbars to a list is the most straightforward and cleanest solution but if the number of Toolbars grows it may become a little tedious to do that. But I wouldn't be surprised to find out that this approach to saving the sates of the toolbars is flawed in the first place :-P .

    Thanx

  7. #7
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: what happened to toolBars() in Qt4?

    Oh, but Qt 4 has a function for that: QMainWindow::saveState().

  8. The following user says thank you to spud for this useful post:

    momesana (25th September 2007)

  9. #8
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: what happened to toolBars() in Qt4?

    Quote Originally Posted by spud View Post
    Oh, but Qt 4 has a function for that: QMainWindow::saveState().
    Oh :-D. Thanks for the hint.

Similar Threads

  1. More problems with Menus and Toolbars
    By mridey in forum Qt Tools
    Replies: 2
    Last Post: 16th November 2006, 11:37
  2. What happened to QCanvas?
    By christian.convey in forum Qt Programming
    Replies: 1
    Last Post: 28th June 2006, 14:14
  3. Why are actions limited to menus and toolbars?
    By Paul Drummond in forum Qt Programming
    Replies: 16
    Last Post: 3rd March 2006, 12:05

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.