Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSettings - counting how many times my app has been opened

QSettings - counting how many times my app has been opened

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 535 Views
  • 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 Offline
    V Offline
    vicarod
    wrote on last edited by
    #1

    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
    0
    • E Offline
      E Offline
      Eeli K
      wrote on last edited by
      #2

      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
      4
      • V Offline
        V Offline
        vicarod
        wrote on last edited by
        #3

        Thanks. It works.

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved