Reference Examples: Use auto for results of new and component.create()
Change-Id: Ibfd92fbc5a99b38cf8b31a11c0adfdfa69e2bb36 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
parent
73a9c52fed
commit
66fabff253
|
@ -62,7 +62,7 @@ int main(int argc, char ** argv)
|
||||||
|
|
||||||
QQmlEngine engine;
|
QQmlEngine engine;
|
||||||
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
||||||
Person *person = qobject_cast<Person *>(component.create());
|
auto *person = qobject_cast<Person *>(component.create());
|
||||||
if (person) {
|
if (person) {
|
||||||
qWarning() << "The person's name is" << person->name();
|
qWarning() << "The person's name is" << person->name();
|
||||||
qWarning() << "They wear a" << person->shoeSize() << "sized shoe";
|
qWarning() << "They wear a" << person->shoeSize() << "sized shoe";
|
||||||
|
|
|
@ -67,7 +67,7 @@ int main(int argc, char ** argv)
|
||||||
|
|
||||||
QQmlEngine engine;
|
QQmlEngine engine;
|
||||||
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
||||||
BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create());
|
auto *party = qobject_cast<BirthdayParty *>(component.create());
|
||||||
|
|
||||||
if (party && party->host()) {
|
if (party && party->host()) {
|
||||||
qWarning() << party->host()->name() << "is having a birthday!";
|
qWarning() << party->host()->name() << "is having a birthday!";
|
||||||
|
|
|
@ -54,7 +54,7 @@ HappyBirthdaySong::HappyBirthdaySong(QObject *parent)
|
||||||
: QObject(parent), m_line(-1)
|
: QObject(parent), m_line(-1)
|
||||||
{
|
{
|
||||||
setName(QString());
|
setName(QString());
|
||||||
QTimer *timer = new QTimer(this);
|
auto *timer = new QTimer(this);
|
||||||
QObject::connect(timer, &QTimer::timeout, this, &HappyBirthdaySong::advance);
|
QObject::connect(timer, &QTimer::timeout, this, &HappyBirthdaySong::advance);
|
||||||
timer->start(1000);
|
timer->start(1000);
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ int main(int argc, char ** argv)
|
||||||
|
|
||||||
QQmlEngine engine;
|
QQmlEngine engine;
|
||||||
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
||||||
BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create());
|
auto *party = qobject_cast<BirthdayParty *>(component.create());
|
||||||
|
|
||||||
if (party && party->host()) {
|
if (party && party->host()) {
|
||||||
qWarning() << party->host()->name() << "is having a birthday!";
|
qWarning() << party->host()->name() << "is having a birthday!";
|
||||||
|
|
|
@ -70,7 +70,7 @@ int main(int argc, char ** argv)
|
||||||
|
|
||||||
QQmlEngine engine;
|
QQmlEngine engine;
|
||||||
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
||||||
BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create());
|
auto *party = qobject_cast<BirthdayParty *>(component.create());
|
||||||
|
|
||||||
if (party && party->host()) {
|
if (party && party->host()) {
|
||||||
qWarning() << party->host()->name() << "is having a birthday!";
|
qWarning() << party->host()->name() << "is having a birthday!";
|
||||||
|
|
|
@ -65,7 +65,7 @@ int main(int argc, char ** argv)
|
||||||
|
|
||||||
QQmlEngine engine;
|
QQmlEngine engine;
|
||||||
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
||||||
BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create());
|
auto *party = qobject_cast<BirthdayParty *>(component.create());
|
||||||
|
|
||||||
if (party && party->host()) {
|
if (party && party->host()) {
|
||||||
qWarning() << party->host()->name() << "is having a birthday!";
|
qWarning() << party->host()->name() << "is having a birthday!";
|
||||||
|
|
|
@ -65,7 +65,7 @@ int main(int argc, char ** argv)
|
||||||
// ![1]
|
// ![1]
|
||||||
QQmlEngine engine;
|
QQmlEngine engine;
|
||||||
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
||||||
QLineEdit *edit = qobject_cast<QLineEdit *>(component.create());
|
auto *edit = qobject_cast<QLineEdit *>(component.create());
|
||||||
// ![1]
|
// ![1]
|
||||||
|
|
||||||
if (edit) {
|
if (edit) {
|
||||||
|
|
|
@ -66,7 +66,7 @@ int main(int argc, char ** argv)
|
||||||
|
|
||||||
QQmlEngine engine;
|
QQmlEngine engine;
|
||||||
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
||||||
BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create());
|
auto *party = qobject_cast<BirthdayParty *>(component.create());
|
||||||
|
|
||||||
if (party && party->host()) {
|
if (party && party->host()) {
|
||||||
qWarning() << party->host()->name() << "is having a birthday!";
|
qWarning() << party->host()->name() << "is having a birthday!";
|
||||||
|
|
|
@ -82,7 +82,7 @@ Person *BirthdayParty::guest(int index) const
|
||||||
|
|
||||||
void BirthdayParty::invite(const QString &name)
|
void BirthdayParty::invite(const QString &name)
|
||||||
{
|
{
|
||||||
Person *person = new Person(this);
|
auto *person = new Person(this);
|
||||||
person->setName(name);
|
person->setName(name);
|
||||||
m_guests.append(person);
|
m_guests.append(person);
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ int main(int argc, char ** argv)
|
||||||
|
|
||||||
QQmlEngine engine;
|
QQmlEngine engine;
|
||||||
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
||||||
BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create());
|
auto *party = qobject_cast<BirthdayParty *>(component.create());
|
||||||
|
|
||||||
if (party && party->host()) {
|
if (party && party->host()) {
|
||||||
qWarning() << party->host()->name() << "is having a birthday!";
|
qWarning() << party->host()->name() << "is having a birthday!";
|
||||||
|
|
|
@ -65,7 +65,7 @@ int main(int argc, char ** argv)
|
||||||
|
|
||||||
QQmlEngine engine;
|
QQmlEngine engine;
|
||||||
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
||||||
BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create());
|
auto *party = qobject_cast<BirthdayParty *>(component.create());
|
||||||
|
|
||||||
if (party && party->host()) {
|
if (party && party->host()) {
|
||||||
qWarning() << party->host()->name() << "is having a birthday!";
|
qWarning() << party->host()->name() << "is having a birthday!";
|
||||||
|
|
|
@ -67,7 +67,7 @@ int main(int argc, char ** argv)
|
||||||
|
|
||||||
QQmlEngine engine;
|
QQmlEngine engine;
|
||||||
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
||||||
BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create());
|
auto *party = qobject_cast<BirthdayParty *>(component.create());
|
||||||
|
|
||||||
if (party && party->host()) {
|
if (party && party->host()) {
|
||||||
qWarning() << party->host()->name() << "is having a birthday!";
|
qWarning() << party->host()->name() << "is having a birthday!";
|
||||||
|
|
|
@ -54,7 +54,7 @@ HappyBirthdaySong::HappyBirthdaySong(QObject *parent)
|
||||||
: QObject(parent), m_line(-1)
|
: QObject(parent), m_line(-1)
|
||||||
{
|
{
|
||||||
setName(QString());
|
setName(QString());
|
||||||
QTimer *timer = new QTimer(this);
|
auto *timer = new QTimer(this);
|
||||||
QObject::connect(timer, &QTimer::timeout, this, &HappyBirthdaySong::advance);
|
QObject::connect(timer, &QTimer::timeout, this, &HappyBirthdaySong::advance);
|
||||||
timer->start(1000);
|
timer->start(1000);
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ int main(int argc, char ** argv)
|
||||||
|
|
||||||
QQmlEngine engine;
|
QQmlEngine engine;
|
||||||
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
||||||
BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create());
|
auto *party = qobject_cast<BirthdayParty *>(component.create());
|
||||||
|
|
||||||
if (party && party->host()) {
|
if (party && party->host()) {
|
||||||
qWarning() << party->host()->name() << "is having a birthday!";
|
qWarning() << party->host()->name() << "is having a birthday!";
|
||||||
|
|
Loading…
Reference in New Issue