Results 1 to 2 of 2

Thread: Declare buttons in .h file or in .cpp file?

  1. #1
    Join Date
    Feb 2006
    Posts
    209
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Declare buttons in .h file or in .cpp file?

    In the Qt examples (t14) I find that they declare buttons and other things in the constructor of the GameBoard class. Is there any special reason for not putting it in the .h file instead?
    The only reason I can think of is that you don't have to write #include <QPushButton> twice. Any better reason?

  2. #2
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Declare buttons in .h file or in .cpp file?

    They don't care about using those widgets after initialization so there's no need wasting memory keeping track of them with pointers.

    Pointers are 32bits or 64bits, depending on your CPU. Thus there are 4 or 8 bytes wasted by widget and by instance of the class :

    Let's imagine you've got an app that create 100 widgets inside a QTabWidget, each of these widget holding 100 children => 100*100*4 = 40kb wasted (or 80 on a 64bit CPU). Then you're using a multi threaded OS aren't you. Asssuming you're runnig 20 apps of the same kind => 20*40 = 800kb (or 1.6 Mb on a 64bit CPU) . Numbers I chose may not seem realistic but IMHO they're an underevaluation of what some beginners do...
    Current Qt projects : QCodeEdit, RotiDeCode

  3. The following user says thank you to fullmetalcoder for this useful post:

    Morea (18th March 2006)

Similar Threads

  1. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 16:21

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.