PDA

View Full Version : Share a variable between forms



sepehr
28th January 2009, 15:48
hey folks,
I wanted to know what would be the best way to share a variable between all forms of my application? I have
QHash<QString,QString> configs;
which configs holds some configuration of my application which multiple forms need to access,what would be the best approach to define configs?
--
thanks in adavnce

spirit
28th January 2009, 15:53
add method to widget which holds this hash and return it, i.e.


QHash<QString,QString> MyWidget::config() const
{
return m_config;
}

sepehr
28th January 2009, 19:13
add method to widget which holds this hash and return it, i.e.


QHash<QString,QString> MyWidget::config() const
{
return m_config;
}


I don't think that would do the job,say I have 2 forms(myWidget and Mywidget2) which are not related at all,so I can't call MyWidget::config() from Mywidget2

spirit
28th January 2009, 19:15
then make this variable global.

sepehr
29th January 2009, 08:05
yeah,that's what I did at first,but using global variables is not recommended,this helped so much
http://geeklab.wikidot.com/cpp-singleton-pattern
and this
http://www.devarticles.com/c/a/Cplusplus/C-plus-plus-In-Theory-The-Singleton-Pattern-Part-I/