Results 1 to 6 of 6

Thread: How to get MainWindow of Application?

  1. #1
    Join Date
    Jun 2007
    Location
    India/Bangalore
    Posts
    156
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up How to get MainWindow of Application?

    Hi all,


    I am using Qt 4.3 , I want to get MainWindow of the particular Application?

    How to do this?
    Thanks,
    Rajesh.S

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to get MainWindow of Application?

    Simple. Make a QMainWindow singleton subclass.

  3. #3
    Join Date
    Jun 2007
    Location
    India/Bangalore
    Posts
    156
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to get MainWindow of Application?

    sorry , I want to get instance of mainwindow of the application from some other classes in the same application.
    Thanks,
    Rajesh.S

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to get MainWindow of Application?

    Yes, I know. And you should do it by implementing your QMainWindow subclass as a singleton.

  5. #5
    Join Date
    Jun 2007
    Location
    India/Bangalore
    Posts
    156
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to get MainWindow of Application?

    we can make qMainWindow as singleton , how to get instance.
    Thanks,
    Rajesh.S

  6. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to get MainWindow of Application?

    Qt Code:
    1. class MyWindow : public QMainWindow
    2. {
    3. private:
    4. static MyWindow* instance;
    5. protected:
    6. MyWindow(QWidget* = NULL);
    7. public:
    8. static MyWindow* getInstance()
    9. {
    10. if(!instance)
    11. {
    12. instance = new MyWindow();
    13. }
    14. return instance;
    15. }
    16. };
    To copy to clipboard, switch view to plain text mode 
    and in the cpp don't forget to initialize the static member to NULL.

    Next, you can use this in other classes just by including the MyWindow header:
    Qt Code:
    1. #include "MyWindow.h"
    2. ...
    3. MyWindow* mainWindow = MyWindow::getInstance();
    4. ...
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Notifying Mainwindow of an event..
    By MrGarbage in forum Qt Programming
    Replies: 1
    Last Post: 9th November 2007, 21:29
  2. Replies: 1
    Last Post: 11th September 2007, 13:34
  3. dll + application
    By fpujol in forum Qt Programming
    Replies: 11
    Last Post: 15th April 2007, 18:37
  4. Replies: 3
    Last Post: 8th December 2006, 18:51

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.