Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business


OverviewFelgo 3 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.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded