PDA

View Full Version : creating a QWidget in the global space



wambagilles
5th May 2011, 06:42
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) ?

ChrisW67
5th May 2011, 07:57
I'm intrigued, what problem are you trying to solve with a static QWidget?

wambagilles
5th May 2011, 12:00
i need to create a single instance of a qwidget that can be used in all classes of the programm.

MarekR22
5th May 2011, 13:30
I don't see a problem. Just use singleton pattern.

// static method
YourWidget* YourWidget::instance()
{
static YourWidget* ins = 0;
if (ins==0)
ins = new YourWidget(qApp);
return ins;
}

wambagilles
8th May 2011, 18:54
yeah, perfect, thanks