Здравствуйте, Макс. Зачем листинге 60.6 используется QQmlComponent?
QT Creator создает код:
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral(“qrc:/main.qml”)));
и из engine.rootObjects() мы получаем ссылку на корневой элемент без использования дополнительных классов.
Антон, да в качестве альтернативы можно обойтись и без QQmlComponent. Тогда код программы будет следующим:
#include
#include
#include “CppConnection.h”
Листинг 60.7:
QMessageBox::information(0, “Message”, “It’s my message”);
Должно быть:
QMessageBox::information(this, “Message”, “It’s my message”);
Иначе при нажатии на список программа вместе с MessageBox теряет фокус и уходит в background.
btw. Макс, есть возможность получить электронный макет книги? Я сначала пользовался сканом, потом купил в озоне бумажную копию, но читать в электронном виде мне все равно удобнее. В том числе потому, что качество издания (бумага) оставляет желать лучшего.
Добрый день.
Программа CPPExtension при запуске выдает d QML debugging console следующее:
qrc:/main.qml:4: ReferenceError: myColor is not defined
qrc:/main.qml:9: ReferenceError: myText is not defined
qrc:/main.qml:13: ReferenceError: myModel is not defined
qrc:/main.qml:4: ReferenceError: myColor is not defined
qrc:/main.qml:9: ReferenceError: myText is not defined
qrc:/main.qml:4: ReferenceError: myColor is not defined
связка происходит кодом:
pcon->setContextProperty(“myModel”, pmodel);
pcon->setContextProperty(“myText”, “It’s my text!”);
pcon->setContextProperty(“myColor”, QColor(Qt::yellow));
pcon->setContextProperty(“myWidget”, this);
Вопрос: почему в QML debugging console выводится информация по myColor, myText, myMode, при этом по myWidget не выводится?
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.AcceptRead More
Privacy & Cookies Policy
Privacy Overview
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
Глава 6 страница 907, опечатка вместо QString::split, QString::slit
Спасибо Андрей, опечатку в следующий раз исправлю.
Здравствуйте, Макс. Зачем листинге 60.6 используется QQmlComponent?
QT Creator создает код:
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral(“qrc:/main.qml”)));
и из engine.rootObjects() мы получаем ссылку на корневой элемент без использования дополнительных классов.
Антон, да в качестве альтернативы можно обойтись и без QQmlComponent. Тогда код программы будет следующим:
#include
#include
#include “CppConnection.h”
// ———————————————————————-
int main(int argc, char** argv)
{
QGuiApplication app(argc,argv);
QQmlApplicationEngine eng;
eng.load(QUrl(“qrc:/main.qml”));
CppConnection cc;
QObject* pobj = eng.rootObjects().first();(“QuitButton”);(“InfoButton”);
QObject* pcmdQuitButton = pobj->findChild
if (pcmdQuitButton) {
QObject::connect(pcmdQuitButton, SIGNAL(quitClicked()),
&cc, SLOT(slotQuit())
);
}
QObject* pcmdInfoButton = pobj->findChild
if (pcmdInfoButton) {
QObject::connect(pcmdInfoButton, SIGNAL(infoClicked(QString)),
&cc, SLOT(slotInfo(QString))
);
}
return app.exec();
}
Листинг 60.7:
QMessageBox::information(0, “Message”, “It’s my message”);
Должно быть:
QMessageBox::information(this, “Message”, “It’s my message”);
Иначе при нажатии на список программа вместе с MessageBox теряет фокус и уходит в background.
btw. Макс, есть возможность получить электронный макет книги? Я сначала пользовался сканом, потом купил в озоне бумажную копию, но читать в электронном виде мне все равно удобнее. В том числе потому, что качество издания (бумага) оставляет желать лучшего.
Спасибо, обязательно учту Ваше замечание. На счет электронного макета, в GooglePlay есть книга в электронном виде, вот ссылка: https://play.google.com/store/books/details/Макс_Шлее_Qt_5_10_Профессиональное_программировани?id=J4N0DwAAQBAJ
Добрый день.
Программа CPPExtension при запуске выдает d QML debugging console следующее:
qrc:/main.qml:4: ReferenceError: myColor is not defined
qrc:/main.qml:9: ReferenceError: myText is not defined
qrc:/main.qml:13: ReferenceError: myModel is not defined
qrc:/main.qml:4: ReferenceError: myColor is not defined
qrc:/main.qml:9: ReferenceError: myText is not defined
qrc:/main.qml:4: ReferenceError: myColor is not defined
связка происходит кодом:
pcon->setContextProperty(“myModel”, pmodel);
pcon->setContextProperty(“myText”, “It’s my text!”);
pcon->setContextProperty(“myColor”, QColor(Qt::yellow));
pcon->setContextProperty(“myWidget”, this);
Вопрос: почему в QML debugging console выводится информация по myColor, myText, myMode, при этом по myWidget не выводится?
Здравствуйте, Егор. Честно говоря, мне странно, что появляется сообщение “ReferenceError:”.