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. Error: Cannot assign JavaScript function to QString
Forum Updated to NodeBB v4.3 + New Features

Error: Cannot assign JavaScript function to QString

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 2.3k Views 1 Watching
  • 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.
  • C Offline
    C Offline
    ConnorLee
    wrote on 16 May 2014, 14:33 last edited by
    #1

    @Rectangle {
    id: confirmButton
    visible: false
    width: 100
    height: 50
    x:100
    y:225
    color: "black"
    border.color:"white"

                MouseArea {
                    id: confirmButtonText
                    anchors.fill: parent
    
                    function addStrings(calcInput1, calcInput2)
                                        {
                                            var Sum=pasteInt(calcInput1)+parseInt(calcInput2)
                                            return Sum
                                        }
    
                    onClicked: result.text = addStrings
                }
                Text {
                    
                    anchors.centerIn: parent
                    text: "confirm"
                    color: "white"
                }
            }
    

    @

    Im very new to QML and QT and I was wondering if anyone could help me with parsing to a Qstring? Thanks

    [edit: added missing coding tags @ SGaist]

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 16 May 2014, 21:00 last edited by
      #2

      Hi,

      You can't assign a JavaScript function to a QString however you can put the result of the function in it.

      Here's a version of your code working

      @
      Rectangle {
      id: confirmButton
      width: 100
      height: 50
      color: "black"
      border.color:"white"

      MouseArea {
          id: confirmButtonText
          anchors.fill: parent
      
          function addStrings(calcInput1, calcInput2)
          {
              var Sum=parseInt(calcInput1)+parseInt(calcInput2)
              return Sum
          }
      
          onClicked: result.text = addStrings(2, 3)
      }
      Text {
          id: result
          anchors.centerIn: parent
          text: "confirm"
          color: "white"
      }
      

      }@

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      1/2

      16 May 2014, 14:33

      • Login

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