Results 1 to 2 of 2

Thread: Is it normal to have a huge MainWindow constructor?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Is it normal to have a huge MainWindow constructor?

    The code to construct the UI has to exist somewhere. If you use Designer it exists in the generate ui_*.h file, in your case it exists in your class.

    There is no perfect answer as to how you arrange it. You might like to improve maintainability by splitting the UI construction code into several private member functions you call from the constructor:
    Qt Code:
    1. void createActions() {...}
    2. void createMenus() {...}
    3. void createToolBars() {...}
    4. void createStatusBar() {...}
    5. void createLayouts() {...}
    6. // ... you get the picture. The break down should suit your UI.
    To copy to clipboard, switch view to plain text mode 

    If you are going to create the same widget several times (esp. from other classes) then you could create a dedicated sub class or just a private factory function.

  2. The following user says thank you to ChrisW67 for this useful post:

    wayfaerer (18th April 2012)

Similar Threads

  1. How to block the normal buttons of a QWidget
    By Momergil in forum Qt Programming
    Replies: 3
    Last Post: 4th January 2012, 12:32
  2. Style sheets bug? Or normal behavior?
    By Syntho in forum Qt Programming
    Replies: 0
    Last Post: 7th June 2010, 09:16
  3. Replies: 1
    Last Post: 28th May 2010, 23:01
  4. Start application minimized or normal
    By matze in forum Qt Programming
    Replies: 3
    Last Post: 12th January 2010, 14:57
  5. can't new qwebview in a mainwindow constructor
    By billconan in forum Qt Programming
    Replies: 4
    Last Post: 15th July 2009, 09:29

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
  •  
Qt is a trademark of The Qt Company.