Results 1 to 4 of 4

Thread: Simple Question on Variable initialization

  1. #1

    Question Simple Question on Variable initialization

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany.
    Posts
    111
    Thanks
    29
    Thanked 3 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Thumbs up Re: Simple Question on Variable initialization

    Well, you could use
    Qt Code:
    1. bool QFile::exists ( const QString & fileName )
    To copy to clipboard, switch view to plain text mode 
    to see if your file exists
    or
    you could use
    QSettings to read a value from the registry which you have written

    Qt Code:
    1. QSettings ( Format format, Scope scope, const QString & organization, const QString & application = QString(), QObject * parent = 0 )
    To copy to clipboard, switch view to plain text mode 
    i.e.
    Qt Code:
    1. QSettings settings(QSettings::SystemScope, "Your name", "Program name");
    To copy to clipboard, switch view to plain text mode 
    and then
    to see if your value has been set
    Qt Code:
    1. blnMyBoolean= settings.value("program_has_been_run_once", 0).toBool();
    2. if (blnBoolean == false)
    3. {
    4. //the program has not been run
    5. //do your stuff
    6. //and set the entry to true
    7. settings.setValue("program_has_been_run_once", true);
    8. }
    To copy to clipboard, switch view to plain text mode 
    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

  3. #3

    Question Re: Simple Question on Variable initialization

    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....

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Simple Question on Variable initialization

    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.

Similar Threads

  1. Debugging and variable initialization
    By fullmetalcoder in forum General Programming
    Replies: 0
    Last Post: 17th February 2009, 18:24
  2. QTextEdit simple question
    By Marcopolo in forum Qt Tools
    Replies: 4
    Last Post: 11th October 2007, 00:01
  3. Variable question
    By MarkoSan in forum General Programming
    Replies: 4
    Last Post: 15th March 2007, 14:59
  4. simple thread layout question
    By mhoover in forum Qt Programming
    Replies: 1
    Last Post: 12th August 2006, 11:02
  5. simple question on Class-Members
    By mickey in forum General Programming
    Replies: 7
    Last Post: 4th February 2006, 22:37

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.