Extending QML - Methods Example
扩展QML-方法示例
Methods Support.
方法支持。
This example builds on:
此示例基于:
- Extending QML - Inheritance and Coercion Example
- Extending QML - Object and List Property Types Example
- Extending QML - Adding Types Example
The Methods Example has an additional method in the BirthdayParty
class: invite()
. invite()
is declared with Q_INVOKABLE so that it can be called from QML.
方法示例在BirthdayParty类中有一个附加方法:invite()
. invite()
是用Q_INVOKABLE声明的,因此可以从QML调用它。
Q_INVOKABLE void invite(const QString &name);
In example.qml
, the invite()
method is called in the Component.onCompleted signal handler:
示例example.qml
,则在Component.onCompleted信号处理器中调用invite()方法:
import QtQuick 2.0
import People 1.0
BirthdayParty {
host: Person {
name: "Bob Jones"
shoeSize: 12
}
guests: [
Person { name: "Leo Hodges" },
Person { name: "Jack Smith" },
Person { name: "Anne Brown" }
]
Component.onCompleted: invite("William Green")
}