示例#1
0
文件: main.py 项目: salticus/learn
from person import Person


# int main(int argc, char ** argv)
if __name__ == '__main__':
    # QCoreApplication app(argc, argv);
    app = QCoreApplication(sys.argv)

    # qmlRegisterType<Person>("People", 1,0, "Person");
    qmlRegisterType(Person, 'People', 1, 0, 'Person');

    # QDeclarativeEngine engine;
    engine = QDeclarativeEngine()

    # QDeclarativeComponent component(&engine, QUrl("qrc:example.qml"));
    component = QDeclarativeComponent(engine, QUrl("example.qml"))

    # Person *person = qobject_cast<Person *>(component.create());
    person = component.create()

    # if (person) {
    if person:
        # qWarning() << "The person's name is" << person->name();
        # qWarning() << "They wear a" << person->shoeSize() << "sized shoe";
        qWarning("The person's name is {p.name}".format(p=person))
        qWarning("They wear a {p.shoeSize} sized shoe".format(p=person))
    # } else {
    else:
        # usual approach failed here: needed extract all the errors from a
        # list, and then cast them to strings.
        # trying to cast to unicode resulted in an incomplete error message