Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. TypeError: property 'xxx' of object is not a function
Forum Updated to NodeBB v4.3 + New Features

TypeError: property 'xxx' of object is not a function

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 Posters 713 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.
  • Y Offline
    Y Offline
    Yazid10
    wrote on 3 Jul 2023, 16:21 last edited by
    #1

    Hi everyone,

    I'm trying to dynamically create buttons using this code :

    Component {
                id: myButton;
    
                Button { }
            }
    
            function addButton () {
                var button = myButton.createObject (root, {
                                                        "color"  : "red",
                                                        "width"  : 50,
                                                        "height" : 80,
                                                        "x"      : 50,
                                                        "y"      : 50
                                                    });
            }
    
            Button {
                anchors.centerIn: parent;
                text: "ok";
    
                onClicked: {
                    root.addButton();
                }
            }
    

    But i keep getting this error :

    TypeError: Property 'addButton' of object PagePanel_QMLTYPE_12(0x1b8024fe490) is not a function.

    Anyone knows how to fix it ? Thanks

    M 1 Reply Last reply 3 Jul 2023, 16:40
    0
    • Y Yazid10
      3 Jul 2023, 16:21

      Hi everyone,

      I'm trying to dynamically create buttons using this code :

      Component {
                  id: myButton;
      
                  Button { }
              }
      
              function addButton () {
                  var button = myButton.createObject (root, {
                                                          "color"  : "red",
                                                          "width"  : 50,
                                                          "height" : 80,
                                                          "x"      : 50,
                                                          "y"      : 50
                                                      });
              }
      
              Button {
                  anchors.centerIn: parent;
                  text: "ok";
      
                  onClicked: {
                      root.addButton();
                  }
              }
      

      But i keep getting this error :

      TypeError: Property 'addButton' of object PagePanel_QMLTYPE_12(0x1b8024fe490) is not a function.

      Anyone knows how to fix it ? Thanks

      M Offline
      M Offline
      mzimmers
      wrote on 3 Jul 2023, 16:40 last edited by
      #2

      @Yazid10 apart from the problem that a Button doesn't have a color property, this works for me:

      ApplicationWindow {
          id: root
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")
          Component {
              id: myButton;
      
              Button { }
          }
      
          function addButton () {
              var button = myButton.createObject (root, {
      //                                                "color"  : "red",
                                                      "width"  : 50,
                                                      "height" : 80,
                                                      "x"      : 50,
                                                      "y"      : 50
                                                  });
          }
      
          Button {
              anchors.centerIn: parent;
              text: "ok";
      
              onClicked: {
                  root.addButton();
              }
          }
      }
      

      What platform and Qt version are you using?

      Y 1 Reply Last reply 3 Jul 2023, 21:11
      0
      • M mzimmers
        3 Jul 2023, 16:40

        @Yazid10 apart from the problem that a Button doesn't have a color property, this works for me:

        ApplicationWindow {
            id: root
            width: 640
            height: 480
            visible: true
            title: qsTr("Hello World")
            Component {
                id: myButton;
        
                Button { }
            }
        
            function addButton () {
                var button = myButton.createObject (root, {
        //                                                "color"  : "red",
                                                        "width"  : 50,
                                                        "height" : 80,
                                                        "x"      : 50,
                                                        "y"      : 50
                                                    });
            }
        
            Button {
                anchors.centerIn: parent;
                text: "ok";
        
                onClicked: {
                    root.addButton();
                }
            }
        }
        

        What platform and Qt version are you using?

        Y Offline
        Y Offline
        Yazid10
        wrote on 3 Jul 2023, 21:11 last edited by
        #3

        @mzimmers I'm using Qt 6.5 on Windows..

        M 1 Reply Last reply 3 Jul 2023, 22:46
        0
        • Y Yazid10
          3 Jul 2023, 21:11

          @mzimmers I'm using Qt 6.5 on Windows..

          M Offline
          M Offline
          mzimmers
          wrote on 3 Jul 2023, 22:46 last edited by
          #4

          @Yazid10 try this, exactly as I've entered it here:

          import QtQuick
          import QtQuick.Controls
          
          ApplicationWindow {
              id: mainWindow
              width: 640
              height: 480
              visible: true
              title: qsTr("Hello World")
              
              Component {
                  id: myButton;
                  Button {
                      onClicked : console.log("clicked!")
                  }
              }
              
              function addButton () {
                  myButton.createObject (mainWindow, {
                                             "width"  : 50,
                                             "height" : 80,
                                             "x"      : 50,
                                             "y"      : 50,
                                         });
              }
              
              Button {
                  anchors.centerIn: parent;
                  text: "ok";
                  
                  onClicked: {
                      addButton();
                  }
              }
          }
          
          1 Reply Last reply
          2

          1/4

          3 Jul 2023, 16:21

          • Login

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