Forums

OverviewFelgo 2 Support (Qt 5) › Populate ComboBox list with data from Firebase

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #19664

    Edward

    Hello!!

    In my Firebase Database I have a section of groups (groups/location1 — groups/location2 — groups/location3 ect ect) I want the contents of a dropdown ComboBox to be the locations taken from my database groups area, to assign users to on registration, how would I fill the list with the locations? at the moment I am using a standard comboBox (see code)

                    Quick2.ComboBox {
                        id: combobox
                        visible: registerCheckbox.checked ? true : false
                        Layout.preferredWidth: dp(200)
                        padding: dp(12)
    
                        model: ["location1", "location2", "location3", "location4", "location5"]
    
                        delegate: Quick2.ItemDelegate {
                        width: combobox.width
                        height: combobox.height
                        padding: dp(12)
                        contentItem: AppText {
                            text: modelData
                            color: highlighted ? Theme.tintColor : Theme.textColor
                            wrapMode: Text.NoWrap
                        }
                        highlighted: combobox.highlightedIndex == index
                    }
                    contentItem: AppText {
                        width: combobox.width - combobox.indicator.width - combobox.spacing
                        text: combobox.displayText
                        wrapMode: Text.NoWrap
                    }
                    }

     

    #19672

    Günther
    Felgo Team

    Hi Edward,

    once you retrieve your stored data from firebase, you can go through the values and set them as the model of the ComboBox.

    Best,
    Günther

    #19864

    Edward

    Hey,

    I have tried to obtain the data by using setting my model as:

      model: [firebaseDb.getValue("groups/CanaryWharf/title"), firebaseDb.getValue("groups/Colchester/title"), firebaseDb.getValue("groups/Ipswich/title"), firebaseDb.getValue("groups/Romford/title")]

     

    and receive the error on the ‘text: modelData’ line:

    Unable to assign [undefined] to QString

    when I click the drop-down box on my registration form it shows blank boxes, the correct amount for my model, but no text within? why is the text not displaying?

     

    Thanks

    Edd

    #19866

    Günther
    Felgo Team

    Hi,

    as mentioned in the Firebase::getValue docs: https://felgo.com/doc/vplayplugins-firebasedatabase/#getValue-method

    Firebase works asynchronously. This means that getValue() will tell Firebase to fetch the value, and when the value is received the callback function triggers, so you can process the value.

    You can also use the readCompleted signal to run code whenever a value is fetched from the database: https://felgo.com/doc/vplayplugins-firebasedatabase/#readCompleted-signal

    Best,
    Günther

    #19907

    Edward

    Hey,

    so I have managed to make this work when my users log in and is displays their name with welcome message by using;

            onLoggedIn: {
                firebaseDb.getUserValue("Firstname", {}, function(success, key, value) {
                                    userName.text = "Welcome " + value
                                  })
            }

     

    but when trying to make this work for the model of my dropdown list I am at an impass, I have tried a few different approaches but none are working :(, based around the below code,

     db.getValue("public/listEntries", {
                       startAt: {
                         key: "startKey",
                         value: "startValue"
                       }
                     }, function(success, key, value) {
                       if(success) {
                         console.log("Read user value for key", key, "from DB:", value)
                         combobox.model = value
                       }
                     })
    

     

    or I have also tried applying the method outlined in the database filtering example in:

    https://felgo.com/doc/plugin-firebase/

    I intend to use the selected item from this dropdown list to assign users to the appropriate subgroup in my realtime database – so also need to be able to add to the code later to do so, also I do not want to explicitly call each value, I need to be able to read values/keys from that branch of the database, so I can add future keys and the list will update from that rather than having to push an update on the app – if that would work

     

    Thanks

    Edd!

     

    #19962

    Günther
    Felgo Team

    Hi Edward,

    we can help out with development of your project or review your source code with the purchase of support package, or the included support of Felgo Indie or Enterprise.

    Let me know if this is interesting for you!

    Best,
    Günther

Viewing 6 posts - 1 through 6 (of 6 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