OverviewFelgo 2 Support (Qt 5) › How to create an array of char/string and use it?

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

    Felgo User

    I create an AppButton then each time user click it, it change the text of the button to the next char/string in an array like this

    import Felgo 3.0
    import QtQuick 2.0
     property var arrayOfChar = ['a', 'b', 'c', 'd', 'e', 'f']
     property string testChar
     onClicked: {
     var numOfChar = entry.length
     var random = utils.generateRandomValueBetween(0, numOfChar-1)
     var testChar = entry[random]
     questButton.text = testChar

    I guessed the text changing will happened easily but I got this errors V_Play_Desktop_Qt_5_11_1_MinGW-Debug/qml/QuestButton.qml:20: Error: Cannot assign [undefined] to QString. What wrong I have done and is there a more standard way to do like I said?


    Felgo Team

    You can do something like this, if you face this error, there’s probably an issue in your user code. Sounds like the value you are trying to fetch does not exist in the array.


    Felgo User

    Thank you for the hint. The problem now can be solved by add Math.round

    var random = Math.round(utils.generateRandomValueBetween(0,numOfChar - 1))

    I didn’t test the output of function generateRandomValueBetween and misunderstanding that it will generate only integer.

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
create apps
create games
cross platform
native performance
3rd party services
game network
level editor
easiest to learn
biggest time saving
best support