PDA

View Full Version : Simple Question on Variable initialization



Naveen
17th March 2006, 10:09
Hi Everyone...

I'm trying to build a small sample application....

when we install (or launch) it on our system for the very first time I want to show a particular number of buttons on its initial Screen (GUI) and i want to show a different number of buttons there after......even if he closes the application and restarts or double clicks on it later after it is installed......

The approaches which i'm following are

I'm putting it in the main Constructor..

1) I'm a taking a boolean variable and checking if is for the very first time or not but the problem is whenever I close the application and double click it once again...it is following the same process (which it is bound to)

2) i'm trying to create a file and check whether it is existing or not.....here
also the file is getting created whenever i start the application...

I guess this could be done with some config file logic or is there any better way of doing this.....Help me out please........;) ;)


Thanks in Advance
Naveen

TheKedge
17th March 2006, 10:24
Well, you could use

bool QFile::exists ( const QString & fileName ) to see if your file exists
or
you could use
QSettings to read a value from the registry which you have written


QSettings ( Format format, Scope scope, const QString & organization, const QString & application = QString(), QObject * parent = 0 )
i.e.

QSettings settings(QSettings::SystemScope, "Your name", "Program name");
and then
to see if your value has been set

blnMyBoolean= settings.value("program_has_been_run_once", 0).toBool();
if (blnBoolean == false)
{
//the program has not been run
//do your stuff
//and set the entry to true
settings.setValue("program_has_been_run_once", true);
}
maybe that helps - I use the registry for all those sort of things. If you're not using windows QSettings will still work fine. It'll write to preference or ini files.
K

Naveen
17th March 2006, 10:39
I'm using WindowsXP and integrated QT with VisualStudio2005.....

Yeah manipulating with Registry could have been possible but Am not dealing anytime with registry here ....

Is there any way where I can hard code or put some dirty logic to get a similar phenomenon......

How else could anyone go about this.....

Thanks a lot for the reply though....

Naveen....

jacek
17th March 2006, 11:01
You could use registry or even a plain text file and add a signature to it that would allow you to detect any changes. Ask Google about HMAC.

Another way would be patching the executable itself, but that's very hackish and I don't know if windows would allow that.