Results 1 to 4 of 4

Thread: Ui namespace

  1. #1
    Join Date
    May 2012
    Posts
    21
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Ui namespace

    normally when creating an instance of the UI
    QMainWindow *w = new QMainWindow();
    Ui::MainWindow *ui = new Ui::MainWindow(w);

    but is is possible to write it as such?

    QMainWindow *w = new QMainWindow();
    MainWindow *ui = new MainWindow(w);

    is there some method we could use to remove the namespace qualifier?


    Also is Ui::MainWindow and Ui_MainWindow equivalent?
    I've read that its equivalent but can't seem to know why.
    Could someone please let me know.

    Thank you

  2. #2
    Join Date
    Apr 2012
    Posts
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Ui namespace

    you can add next line in cpp-file header

    using namespace Ui;

  3. #3
    Join Date
    Jan 2006
    Posts
    368
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Ui namespace

    Quote Originally Posted by AlekseyOk View Post
    you can add next line in cpp-file header

    using namespace Ui;
    Please don't do this in the header. Leave the headers without any namespace inclusion - let the developer choose which namespace to "use". Otherwise you might get collisions in symbols - which is exactly what namespaces try to fix.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,690
    Thanks
    13
    Thanked 1,599 Times in 1,527 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Ui namespace

    Quote Originally Posted by ashboi View Post
    Also is Ui::MainWindow and Ui_MainWindow equivalent?
    I've read that its equivalent but can't seem to know why.
    Could someone please let me know.
    Read the output of the uic tool.

    When uic generates code from a .ui it creates a class called Ui_Form that implements the setupUi() function you call. It also creates a derived class Form that it places in the Ui namespace.

    I am not sure of the history of this split arrangement but is suspect it is that way to not break legacy code using Ui_Form directly, while ensuring new code uses the Ui namespace so that (eventually) uic can put everything into namespace Ui. Perhaps some very old compilers did not understand "namespace" and this split arrangement allows them to still function.

    All the documentation uses the class in namespace Ui so it would be unwise to rely on the presence of Ui_Form in new code.

Similar Threads

  1. using namespace VS using
    By jryans10 in forum General Programming
    Replies: 1
    Last Post: 7th January 2012, 23:23
  2. QTM namespace
    By Aman607 in forum Qt Programming
    Replies: 1
    Last Post: 13th June 2011, 09:00
  3. QTest Namespace
    By chandan in forum Newbie
    Replies: 2
    Last Post: 4th October 2010, 10:45
  4. QTSoapMessage namespace
    By ken123 in forum Qt Programming
    Replies: 0
    Last Post: 26th July 2010, 22:36
  5. using namespace with VS integration
    By jan in forum Qt Tools
    Replies: 0
    Last Post: 29th September 2009, 05:20

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.