git clone https://github.com/codingburgas/10grade-christmas-luck-pattern-coders.git
/* src/application.cpp : 105 */
engine.rootContext()->setContextProperty("application", this);
In the following code block signal message of Application object is being emitted.
/* src/application.cpp : 132 */
emit message(QString::fromStdString(m.title), QString::fromStdString(m.description), QString::fromStdString(m.type));
After that, "Connections" object listens to signals on application object, which was exposed to qml earlier, and invokes onMessage function, when message signal is emitted. After that this function creates a message widget, which can be visible to user.
/* assets/ui/Application.qml : 89 */
Connections{
target: application
function onMessage(title, description, type){
let messageComponent = Qt.createComponent( Qt.resolvedUrl("Message.qml") )
let waitFunction = () => {
if (messageComponent.status == Component.Ready){
let message = messageComponent.createObject(
mainWindow,
{
title: title,
description: description,
type: type
});
message.destroy(2000)
}else if (newComponent.status === Component.Loading) {
newComponent.statusChanged.connect(waitFunction); // Connect to statusChanged if still loading
}
}
waitFunction();
}
}
NOTE: The function you are calling from qml MUST have Q_INVOKABLE macro.
/* assets/ui/MainPage.qml : 627 */
application.searchWords(searchInput.text, property2ComboBox.getProperty(), caseSensitiveCheckBox.checked, (propertyHasToComboBox.currentIndex==1), (propertyHasToComboBox.currentIndex==2))
In this code method searchWords of application is called to search words with specific properties and update the UI