Forums

OverviewFelgo 2 Support (Qt 5) › Count number of app starts

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #21935

    Edward

    Hey!

    I need to count the number of app starts, as only on the first launch do I need my users to agree to the privacy policy/terms of service! I found on;

     

    https://felgo.com/doc/apps-howtos/#save-things-in-a-local-database

     

    the section of:

     import Felgo 3.0
     import QtQuick 2.5
    
     App {
    
       // define Storage item for loading/storing key-value data
       Storage {
         id: localStorage
         property int appStarts: 0
    
         // update app starts counter
         Component.onCompleted: {
           var nr = localStorage.getValue("appstarts")
           if(nr === undefined)
             nr = 0
    
           nr++
           localStorage.setValue("appstarts", nr)
           appStarts = nr
         }
       }
    
       // define page that shows nr of app starts
       NavigationStack {
    
         Page {
           id: page
           title: "Local Storage"
    
           AppText {
             anchors.centerIn: parent
             text: "App Starts: "+localStorage.appStarts
           }
         }
       }
     }

    and have added to my main.qml, but I still get the popup each time my users launch the app?

    the visibility of the item I want show/hide is on a separate page, loginPage.qml, and the visibility is:

     

    Item {
    
            id: termsAccept
    
            visible: localStorage.appStarts > 1 ? false : true
    
            enabled: localStorage.appStarts > 1 ? false : true
    }

     

    WHat could I change to sort this?

     

    Thanks 🙂

    #21946

    Alex
    Felgo Team

    Hi Edward,

    do you see no issue in the log output? From the code you posted, there is nothing suspicious jumping to my eye. Does the text display the correct value for the number of app starts?

    Cheers,
    Alex

    #21949

    Edward

    Hi Alex,

    It was not counting as the popup showed on every launch, however I found another example on the storage page which uses a Boolean flag which works as intended!

    Thanks!

        Storage {
            id: myLocalStorage
    
            Component.onCompleted: {
    
              var isFirstStartApplication = myLocalStorage.getValue("firstStart")
              if(isFirstStartApplication == undefined) {
                applicationFirstStart = true
              }
    
              myLocalStorage.setValue("firstStart", true)
            }
        }

     

Viewing 3 posts - 1 through 3 (of 3 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support