Qt-interest Archive, February 2007
Declaring a global Qsettings ?
Pages: Prev | 1 | 2 | 3 | Next
Message 1 in thread
I'm trying to use a Qsettings at global scope.
I would like to avoid declaring every here and there in my application
QSetting settings("myProg");
for having access to settings.value();
I have tried several syntaxes to be able to declare settings as a QSettings
in my 'global.h', and then access the values from everywhere, but I did not
succeed.
Any idea ?
--
[ signature omitted ]
Message 2 in thread
what about using a Singleton?
http://www.dofactory.com/Patterns/PatternSingleton.aspx
eb wrote:
> I'm trying to use a Qsettings at global scope.
>
> I would like to avoid declaring every here and there in my application
> QSetting settings("myProg");
> for having access to settings.value();
>
> I have tried several syntaxes to be able to declare settings as a QSettings
> in my 'global.h', and then access the values from everywhere, but I did not
> succeed.
>
> Any idea ?
>
>
>
--
[ signature omitted ]
Message 3 in thread
Thanks for the proposal, but you can call me thick.
This is too complicated for me (I'm not a programmer)
As a matter of fact, I was looking for a syntax *simpler* than
writing several QSetting settings("myProg") in the code.
But if the above ends up being the most straightforward way of doing things,
then be it.
thanks anyway.
Manuela Hutter wrote:
> what about using a Singleton?
> http://www.dofactory.com/Patterns/PatternSingleton.aspx
>
>
>
> eb wrote:
>> I'm trying to use a Qsettings at global scope.
>>
>> I would like to avoid declaring every here and there in my application
>> QSetting settings("myProg");
>> for having access to settings.value();
>>
>> I have tried several syntaxes to be able to declare settings as a
>> QSettings in my 'global.h', and then access the values from everywhere,
>> but I did not succeed.
>>
>> Any idea ?
>>
>>
>>
--
[ signature omitted ]
Message 4 in thread
On Sat, Feb 24, 2007 at 09:21:36PM +0100, eb wrote:
> Thanks for the proposal, but you can call me thick.
> This is too complicated for me (I'm not a programmer)
Actually the singleton is by far the easiest pattern.
If you can use QSettings, you won't have problems to
unterstand it.
Just define in your header file:
class Settings{
public:
static Settings *Instance();
void MethodINeed(void);
<even more methods>
private:
// Make your constructors private
Settings();
Settings(const Settings&);
Settings& operator= (const Settings&);
};
And implement:
Settings *Settings::Instance()
{
static Settings inst;
return &inst;
}
void Settings::MethodINeed(void){
<whatsoever>
}
...
You can then use it like:
Settings::Instance()->MethodINeed();
Just include the appropriat header file.
Ok, it can be done even nicer using extra
namespaces and non-member functions accessing
the singleton, but let's start simple. :-)
Guido
--
[ signature omitted ]
Message 5 in thread
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Guido Seifert schrieb:
> Actually the singleton is by far the easiest pattern.
> If you can use QSettings, you won't have problems to
> unterstand it.
>
That's not a singleton. In your case every call of Settings::instance()
create a new instance of Settings. I added some lines of code to make
your example a real singleton.
> Just define in your header file:
>
> class Settings{
>
> public:
>
> static Settings *Instance();
>
> void MethodINeed(void);
>
> <even more methods>
>
> private:
>
> // Make your constructors private
>
> Settings();
>
> Settings(const Settings&);
>
> Settings& operator= (const Settings&);
static Settings *m_settings;
> };
>
> And implement:
>
> Settings *Settings::Instance()
> {
if (m_settings == 0)
{
m_settings = new Settings();
}
return m_settings;
> }
>
> void Settings::MethodINeed(void){
> <whatsoever>
> }
>
You can take a look at my Config class:
http://svn.berlios.de/wsvn/qsvn/trunk/src/config.h?op=file&rev=0&sc=0
http://svn.berlios.de/wsvn/qsvn/trunk/src/config.cpp?op=file&rev=0&sc=0
- --
Andreas 'ar' Richter
http://www.oszine.de - http://ar.oszine.de
GPG-KeyID: 0x7BA12DD9
Fingerprint: D2E9 202B F4F0 EB16 25DE 5FF7 0CF2 3C57 7BA1 2DD9
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFF4pW1DPI8V3uhLdkRAi7+AJ9Ix6w8PIxkApmSv2p62URyLBhZ5ACeMyjM
bCX71V37NN+i331lxMw0STQ=
=QUKC
-----END PGP SIGNATURE-----
--
[ signature omitted ]
Message 6 in thread
Andreas Richter wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Guido Seifert schrieb:
>> Actually the singleton is by far the easiest pattern.
>> If you can use QSettings, you won't have problems to
>> unterstand it.
>>
>
> That's not a singleton. In your case every call of Settings::instance()
> create a new instance of Settings. I added some lines of code to make
> your example a real singleton.
It _IS_ a real singleton as the QSettings is declared _static_
Matthieu
--
[ signature omitted ]
Message 7 in thread
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Matthieu Brucher schrieb:
> Andreas Richter wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Guido Seifert schrieb:
>>> Actually the singleton is by far the easiest pattern. If you can use
>>> QSettings, you won't have problems to unterstand it.
>>>
>>
>> That's not a singleton. In your case every call of Settings::instance()
>> create a new instance of Settings. I added some lines of code to make
>> your example a real singleton.
>
> It _IS_ a real singleton as the QSettings is declared _static_
Really? That works? It's new for me. I'll try it out. Thanks for the hint :)
- --
Andreas 'ar' Richter
http://www.oszine.de - http://ar.oszine.de
GPG-KeyID: 0x7BA12DD9
Fingerprint: D2E9 202B F4F0 EB16 25DE 5FF7 0CF2 3C57 7BA1 2DD9
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFF4pzFDPI8V3uhLdkRAotEAKDY+63n5XmrvkMiLxFQ6qLLirZOJwCfUYSC
q7M17F2qHzLsEs6PC71NU6U=
=tJtM
-----END PGP SIGNATURE-----
--
[ signature omitted ]
Message 8 in thread
Andreas Richter wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Matthieu Brucher schrieb:
>> Andreas Richter wrote:
>>> -----BEGIN PGP SIGNED MESSAGE-----
>>> Hash: SHA1
>>>
>>> Guido Seifert schrieb:
>>>> Actually the singleton is by far the easiest pattern. If you can use
>>>> QSettings, you won't have problems to unterstand it.
>>>>
>>> That's not a singleton. In your case every call of Settings::instance()
>>> create a new instance of Settings. I added some lines of code to make
>>> your example a real singleton.
>> It _IS_ a real singleton as the QSettings is declared _static_
>
> Really? That works? It's new for me. I'll try it out. Thanks for the hint :)
Yes, it works, I use it for mono-threaded application, simple, but not
very secure, one has to know its limitations - lifetime, reentrancy, ... -
Matthieu
--
[ signature omitted ]
Message 9 in thread
> I have tried several syntaxes to be able to declare settings as a QSettings
> in my 'global.h', and then access the values from everywhere, but I did not
> succeed.
>
> Any idea ?
Singleton?
Guido
--
[ signature omitted ]
Message 10 in thread
one of the most famous design patterns.
a class that allows the instantiation of only one object.
the constructor is private, and a static 'getInstance' method returns the object..
(see the link that I posted in the previous message for a code example)
manu
Guido Seifert wrote:
>> I have tried several syntaxes to be able to declare settings as a QSettings
>> in my 'global.h', and then access the values from everywhere, but I did not
>> succeed.
>>
>> Any idea ?
>
> Singleton?
>
> Guido
>
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
--
[ signature omitted ]
Message 11 in thread
oh, sorry, I guess I misunderstood your posting as a question ;-)
Manuela Hutter wrote:
> one of the most famous design patterns.
> a class that allows the instantiation of only one object.
> the constructor is private, and a static 'getInstance' method returns
> the object..
> (see the link that I posted in the previous message for a code example)
>
> manu
>
>
> Guido Seifert wrote:
>>> I have tried several syntaxes to be able to declare settings as a
>>> QSettings
>>> in my 'global.h', and then access the values from everywhere, but I
>>> did not
>>> succeed.
>>>
>>> Any idea ?
>>
>> Singleton?
>>
>> Guido
>>
>>
>> --
>> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
>> "unsubscribe" in the subject or the body.
>> List archive and information: http://lists.trolltech.com/qt-interest/
--
[ signature omitted ]
Message 12 in thread
On Sat, Feb 24, 2007 at 09:11:41PM +0100, Manuela Hutter wrote:
> oh, sorry, I guess I misunderstood your posting as a question ;-)
Yep, can happen. :-)
Additionally there seems the be a little time warp here. I get the posts
in a somewhat confusing order.
Guido
--
[ signature omitted ]
Message 13 in thread
> Additionally there seems the be a little time warp here. I get the
posts
> in a somewhat confusing order.
>
> Guido
>
Well.. jump to your left... a step to right... put your hands on your
hips.. a pelvic thrust, followed by a hip swivel... Then "Lets do the
Time warp again..."
Sorry just feeling goofy
Scott
Message 14 in thread
Careful, statements like this:
> Well.. jump to your left... a step to right... put your hands on your
> hips.. a pelvic thrust, followed by a hip swivel... Then "Lets do the
> Time warp again..."
allow to draw conclusions about your age. Still have all you original
teeth?
> Sorry just feeling goofy
> Scott
Me too,
Guido :-P
--
[ signature omitted ]
Message 15 in thread
awesome!!
I never understood why some people don't believe that programmers can be humorous..
by the way, do you know the favourite hobby of a bit?
.. bus-driving!
cheers,
manu.
Scott Aron Bloom wrote:
>> Additionally there seems the be a little time warp here. I get the posts
>
>> in a somewhat confusing order.
>
>>
>
>> Guido
>
>>
>
>
> Well.. jump to your left... a step to right... put your hands on your
> hips.. a pelvic thrust, followed by a hip swivel… Then “Lets do the Time
> warp again...”
>
> Sorry just feeling goofy
> Scott
>
--
[ signature omitted ]
Pages: Prev | 1 | 2 | 3 | Next