Results 1 to 5 of 5

Thread: creating a QWidget in the global space

  1. #1
    Join Date
    Feb 2011
    Posts
    55
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default creating a QWidget in the global space

    please i need help, for my programm i need to have a static attribute in a class, but that attribute should be a QWidget, i tried it, but the programm will crash becaused i initialised it in the global space, and it had no parent.

    i had no issue creating static QString attributes and initialising them in the global space.

    please how could i do to the same, but with a QWidget (that needs a parent) ?

  2. #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: creating a QWidget in the global space

    I'm intrigued, what problem are you trying to solve with a static QWidget?

  3. #3
    Join Date
    Feb 2011
    Posts
    55
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: creating a QWidget in the global space

    i need to create a single instance of a qwidget that can be used in all classes of the programm.

  4. #4
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: creating a QWidget in the global space

    I don't see a problem. Just use singleton pattern.
    Qt Code:
    1. // static method
    2. YourWidget* YourWidget::instance()
    3. {
    4. static YourWidget* ins = 0;
    5. if (ins==0)
    6. ins = new YourWidget(qApp);
    7. return ins;
    8. }
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to MarekR22 for this useful post:

    wambagilles (8th May 2011)

  6. #5
    Join Date
    Feb 2011
    Posts
    55
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: creating a QWidget in the global space

    yeah, perfect, thanks

Similar Threads

  1. creating QWidget Plugins
    By Spooky in forum Qt Programming
    Replies: 15
    Last Post: 26th January 2011, 08:58
  2. Replies: 0
    Last Post: 2nd May 2010, 02:55
  3. Problem creating a QWidget using threads
    By tarod in forum Qt Programming
    Replies: 1
    Last Post: 16th November 2007, 12:45
  4. Creating a global array in my code???
    By therealjag in forum General Programming
    Replies: 5
    Last Post: 13th March 2006, 11:13
  5. creating a global instance
    By skatakam in forum General Programming
    Replies: 6
    Last Post: 24th February 2006, 16:26

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.