main.cpp Example File
referenceexamples/grouped/main.cpp
#include <QCoreApplication>
#include <QQmlEngine>
#include <QQmlComponent>
#include <QDebug>
#include "birthdayparty.h"
#include "person.h"
int main(int argc, char ** argv)
{
QCoreApplication app(argc, argv);
qmlRegisterType<BirthdayParty>("People", 1,0, "BirthdayParty");
qmlRegisterType<ShoeDescription>();
qmlRegisterType<Person>();
qmlRegisterType<Boy>("People", 1,0, "Boy");
qmlRegisterType<Girl>("People", 1,0, "Girl");
QQmlEngine engine;
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create());
if (party && party->host()) {
qWarning() << party->host()->name() << "is having a birthday!";
if (qobject_cast<Boy *>(party->host()))
qWarning() << "He is inviting:";
else
qWarning() << "She is inviting:";
Person *bestShoe = nullptr;
for (int ii = 0; ii < party->guestCount(); ++ii) {
Person *guest = party->guest(ii);
qWarning() << " " << guest->name();
if (!bestShoe || bestShoe->shoe()->price() < guest->shoe()->price())
bestShoe = guest;
}
if (bestShoe)
qWarning() << bestShoe->name() << "is wearing the best shoes!";
} else {
qWarning() << component.errors();
}
return 0;
}