Results 1 to 4 of 4

Thread: QT_BEGIN_NAMESPACE question

  1. #1
    Join Date
    Jun 2010
    Posts
    8
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QT_BEGIN_NAMESPACE question

    Hi,
    What is the diference in using ...
    Qt Code:
    1. QT_BEGIN_NAMESPACE
    2. class QLabel;
    3. class QUdpSocket;
    4. QT_END_NAMESPACE
    To copy to clipboard, switch view to plain text mode 

    or
    Qt Code:
    1. #include <QLabel>
    2. #include <QPushButton>
    3. #include <QUdpSocket>
    To copy to clipboard, switch view to plain text mode 

    ... in my dialogs?
    Thanks

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QT_BEGIN_NAMESPACE question

    The first method can be faster; the compiler doesn't need to process the contents of the header files as it does in the second method. This only affects compilation time, and on the systems I've used there is no perceptible difference in compilation speed. On large projects, or where you have a large number of include files, it may make more of a difference.

  3. The following 2 users say thank you to SixDegrees for this useful post:

    khanhsk (12th April 2011), veraS (3rd July 2010)

  4. #3
    Join Date
    Jun 2010
    Posts
    8
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QT_BEGIN_NAMESPACE question

    In the broadcastreceiver example i have:
    Qt Code:
    1. #ifndef RECEIVER_H
    2. #define RECEIVER_H
    3.  
    4. #include <QDialog>
    5.  
    6. QT_BEGIN_NAMESPACE
    7. class QLabel;
    8. class QUdpSocket;
    9. QT_END_NAMESPACE
    10.  
    11. class Receiver : public QDialog
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. Receiver(QWidget *parent = 0);
    17.  
    18. private slots:
    19. void processPendingDatagrams();
    20.  
    21. private:
    22. QLabel *statusLabel;
    23. QPushButton *quitButton;
    24. QUdpSocket *udpSocket;
    25. };
    26.  
    27. #endif
    To copy to clipboard, switch view to plain text mode 

    Why use #include for the QDialog class and QT_BEGIN_NAMESPACE...QT_END_NAMESPACE for QLabel, QPushButton and QUdpSocket?

  5. #4
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QT_BEGIN_NAMESPACE question

    Because Receiver inherits from QDialog; the compiler needs the actual class definition provided in the header file in order to resolve the internal structure of the class. The other classes are only referenced through pointers, so a simple forward declaration is sufficient for the compiler in those cases.
    Last edited by SixDegrees; 3rd July 2010 at 15:48.

  6. The following 2 users say thank you to SixDegrees for this useful post:

    khanhsk (12th April 2011), veraS (3rd July 2010)

Similar Threads

  1. What is the benefit of QT_BEGIN_NAMESPACE?
    By Spectralist in forum Newbie
    Replies: 2
    Last Post: 12th December 2009, 10:40
  2. What's effect of QT_BEGIN_NAMESPACE? Thanks
    By mihayinoviki in forum Qt Programming
    Replies: 10
    Last Post: 19th August 2009, 19: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.