标题:通过组件文件动态创件组件始终失败
作者:石头轩
日期:2015-09-23 15:25
内容:
通过组件文件动态创建组件,定义了一个单独的方法,然后通过button的onClicked信号处理器调用,始终提示方法未定义,这是怎么回事哪?请解答
import QtQuick 2.4import QtQuick.Window 2.2import QtQuick.Controls 1.2;Window {visible: true width:360; height: 300Rectangle{id:rootItem;width: parent.width;height:parent.height;property int count: 0;property Component component: null;
Text{id:coloredText;width: 200;text:"control your propation,keep on smile";anchors.centerIn: parent;font.pixelSize: 18wrapMode:Text.WordWrap;color:"red";}function[color=#c0 ..
#1 [tylan 09-23 17:16]
代码弄成这样,怎么看?
#2 [石头轩 09-23 17:21]
解决了,button信号处理器连接的方法是父级对象的方法,所以要加上父级对象。
onClicked: {
rootItem.createColorPicker(Qt.rgba(Math.random(),Math.random(),Math.random(),1));
}
#3 回 tylan 的帖子 [石头轩 09-23 17:23]
tylan:代码弄成这样,怎么看? (2015-09-23 17:16)
直接减下来,贴到你的开发环境中就行了,
这个也不是我整的,我贴了代码进去他就成这样了,不关我的事啊
#4 回 tylan 的帖子 [石头轩 09-23 17:30]
tylan:代码弄成这样,怎么看? (2015-09-23 17:16)
this is mycode
import QtQuick 2.4
import QtQuick.Window 2.2
import QtQuick.Controls 1.2;
Window {
visible: true
width:360;
height: 300
Rectangle{
id:rootItem;
width: parent.width;
height:parent.height;
property int count: 0;
property Component component: null;
property int yCount:0;
Text{
id:coloredText;
width: 200;
text:"control your propation,keep on smile";
anchors.centerIn: parent;
font.pixelSize:18
wrapMode:Text.WordWrap;
color:"red";
}
function changeTextColor(clr)
{
coloredText.color=clr;
}
functionsetCommpentX()
{
if (rootItem.count*55>rootItem.width)
{
count=0;
ycount++;
}
return count*55+1;
}
function createColorPicker(clr)
{
if(rootItem.component==null)
{
rootItem.component=Qt.createComponent("ColorPicker.qml");
}
var colorPicker;
if(rootItem.component.status==Component.Ready)
{
colorPicker=rootItem.component.createObject(
rootItem,
{"color":clr,"x":setCommpentX(),"y":10*yCount}
..