[Interest] Global QML slot?

Jürgen Bocklage-Ryannel juergen.bocklage-ryannel at pelagicore.com
Thu Nov 8 05:14:05 CET 2012


Looks good, but I would use id's to make sure the signal arrives on the right element.  Your UI structure changes and Id's give you more control.

    
Row {
	id: row
        signal someOtherEvent(int number)
        Repeater {
            model: 10
            delegate: MyRectangle {
                onSomeEvent: { row.someOtherEvent(index) }
                color: "red"
            }
        }
    }
		
/ juergen



On Nov 8, 2012, at 12:08 AM, Mark <markg85 at gmail.com> wrote:

> On Wed, Nov 7, 2012 at 11:56 PM, Nicolás Ulrich <nikolaseu at gmail.com> wrote:
>> I'm still new at QML but... can't you do something like this?
>> (assuming MyRectangle is declared on other file, as you said)
>> 
>>     Row {
>>         Repeater {
>>             signal someOtherEvent(int number)
>>             model: 10
>>             delegate: MyRectangle {
>>                 onSomeEvent: { parent.someOtherEvent(index) }
>>                 color: "red"
>>             }
>>         }
>>     }
>> 
>> or even use a function inside "onSomeEvent:{}"
>> 
>> 
>> On Wed, Nov 7, 2012 at 7:35 PM, Mark <markg85 at gmail.com> wrote:
>>> Hi,
>>> 
>>> I have this case where i'm emitting a signal inside a repetitive
>>> structure like so:
>>> 
>>>    Row {
>>>        Repeater {
>>>            model: 10
>>>            delegate: MyRectangle {
>>>                signal someEvent(int number)
>>>                color: "red"
>>> 
>>>                MouseArea {
>>>                    anchors.fill: parent
>>>                    onClicked: {
>>>                        parent.someEvent(index)
>>>                    }
>>>                }
>>>            }
>>>        }
>>>    }
>>> 
>>> In this case the delegate is a MyRectangle for demonstration purposes.
>>> In reality that delegate is separated out in a new file.
>>> 
>>> The question is, how can i catch all those "someEvent" signals in one slot?
>>> 
>>> I was hoping to be able to do something like:
>>> MyRectangle.onSomeEvent: {
>>>    ...
>>> }
>>> 
>>> But that doesn't work. The intention here was that
>>> MyRectangle.onSomeEvent would catch all the "someEvent" signals from
>>> the repeater..
>>> 
>>> Any ideas..?
>>> 
>>> Cheers,
>>> Mark
>>> _______________________________________________
>>> Interest mailing list
>>> Interest at qt-project.org
>>> http://lists.qt-project.org/mailman/listinfo/interest
> 
> That works.. But it feels a bit nasty :p
> Oh well, using that now.
> 
> It's actually not using signal/slot connection anymore. It's just
> calling a function in the element one level above the repeater.
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20121108/7442811d/attachment.html>


More information about the Interest mailing list