TypeError: property 'xxx' of object is not a function
-
wrote on 3 Jul 2023, 16:21 last edited by
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
-
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
wrote on 3 Jul 2023, 16:40 last edited by@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?
-
@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?
-
wrote on 3 Jul 2023, 22:46 last edited by
@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/4