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. QML Problems
Forum Updated to NodeBB v4.3 + New Features

QML Problems

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.7k 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.
  • S Offline
    S Offline
    SteveG
    wrote on last edited by
    #1

    I have a QML file that contains the excerpt
    @
    Utils{
    id: myUtils
    }
    TextArea {
    id: myTextArea
    readOnly: true
    text: ""
    }
    TextField{
    id: myTextField
    placeholderText: "Enter text"
    }
    Button {
    id: myButton
    text: "Submit"
    onClicked: {
    myUtils.addRow("myTextArea", myTextField.text)
    }
    }
    @

    and a QML file Utils.qml that contains the excerpt
    @
    function addRow(textAreaId, text){
    textAreaId.append("<i>" + text + "</i>");
    }
    @

    The problems I'm having are:

    The error message "TypeError: Property 'append' of object myTextArea is not a function" is produced.

    It works when I replace textAreaId.append by myTextArea.append in addRow but I want a more general solution. [BTW, I am not interested in solutions that use eval.]

    "<i>" + text + "</i>" appears in myTextArea instead of text being italicized when I make the change indicated in 1.

    Any suggestions?

    Thanks.

    Steve

    1 Reply Last reply
    0
    • A Offline
      A Offline
      ahmad88me
      wrote on last edited by
      #2

      Because you are passing is as text, try to pass it by id

      inside the main.qml:

      Utils{
          id: mine
      }
      
      TextArea{
          id: mytf
          width: parent.width
          height: parent.height
      }
      
      MouseArea{
          anchors.fill: parent
          onClicked: {
              mine.ap(mytf,"mytest")
              console.debug("clicked")
          }
      }
      

      in Utils.qml:

      import QtQuick 2.0
      Rectangle {
      width: 100
      height: 62
      function ap(tf,t){
      tf.append(t)
      }
      }

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SteveG
        wrote on last edited by
        #3

        Changing
        @
        myUtils.addRow("myTextArea", myTextField.text)
        @

        to
        @
        myUtils.addRow(myTextArea, myTextField.text)
        @

        solved the first problem. Any suggestions for the second problem?

        Thanks.

        Steve

        1 Reply Last reply
        0

        • Login

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