Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved QSettings - counting how many times my app has been opened

    General and Desktop
    2
    3
    376
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • V
      vicarod last edited by

      How can I make qt counting how many times my app has been opened ? I tried QtSettings but I do not know how to initialize first time the counter so the next time I restart the app, the counter get the value from QSettings, not from initialized value. I tried to do that in the main windows constructor.

      1 Reply Last reply Reply Quote 0
      • E
        Eeli K last edited by

        It's basic usage of QSettings, just give it a default value:

        int i = settings.value("counter", 0).toInt();
        settings.setValue("counter", ++i);
        

        Actually it's clearly stated in the documentation, and also it's said that if the settings isn't found (hasn't been set previously), it returns a null QVariant which means 0 as an int, so you don't even have to give it the default value.

        1 Reply Last reply Reply Quote 4
        • V
          vicarod last edited by

          Thanks. It works.

          1 Reply Last reply Reply Quote 1
          • First post
            Last post