diff options
author | link2xt <link2xt@testrun.org> | 2021-03-16 03:30:19 +0300 |
---|---|---|
committer | link2xt <link2xt@testrun.org> | 2021-03-19 03:13:33 +0300 |
commit | bb9cf9564f9933928ded677809ccd8f9b0980d12 (patch) | |
tree | 9b074f804e435b2d27e3d3c8d9834162a70e4be5 | |
parent | 9cc440eb5bf56b16ef6ea4bf2061f57d0c4b4e4a (diff) | |
download | kdeltachat-bb9cf9564f9933928ded677809ccd8f9b0980d12.tar.gz kdeltachat-bb9cf9564f9933928ded677809ccd8f9b0980d12.zip |
Use Connections to connect signals in QML
-rw-r--r-- | qml/ChatPage.qml | 44 | ||||
-rw-r--r-- | qml/ChatlistPage.qml | 21 |
2 files changed, 28 insertions, 37 deletions
diff --git a/qml/ChatPage.qml b/qml/ChatPage.qml index 1862b44..4496954 100644 --- a/qml/ChatPage.qml +++ b/qml/ChatPage.qml @@ -48,44 +48,36 @@ Kirigami.ScrollablePage { } } - signal chatModified() - onChatModified: { - console.log("CHAT MODIFIED!") - } - - signal incomingEvent() - onIncomingEvent: { - console.log("EVENT!") - } - ListModel { id: messagelistModel } - signal incomingMessage() - onIncomingMessage: { - console.log("Incoming message for chat " + chatId) + Connections { + target: chatPage.eventEmitter - if (chatId == chatPage.chatId) { - updateMessagelist() + function onIncomingEvent() { + console.log("EVENT!") } - } + function onChatModified() { + console.log("CHAT MODIFIED!") + } + function onIncomingMessage() { + console.log("Incoming message for chat " + chatId) - signal messagesChanged(var accountId, int chatId, int msgId) - onMessagesChanged: { - console.log("Messages changed for chat " + chatId) + if (chatId == chatPage.chatId) { + updateMessagelist() + } + } + function onMessagesChanged(accountId, chatId, msgId) { + console.log("Messages changed for chat " + chatId) - if (chatId == chatPage.chatId) { - updateMessagelist() + if (chatId == chatPage.chatId) { + updateMessagelist() + } } } Component.onCompleted: { - eventEmitter.onIncomingEvent.connect(incomingEvent) - eventEmitter.onChatModified.connect(chatModified) - eventEmitter.onIncomingMessage.connect(incomingMessage) - eventEmitter.onMessagesChanged.connect(messagesChanged) - updateMessagelist() } diff --git a/qml/ChatlistPage.qml b/qml/ChatlistPage.qml index dfc41f0..a6c3795 100644 --- a/qml/ChatlistPage.qml +++ b/qml/ChatlistPage.qml @@ -13,21 +13,20 @@ Kirigami.ScrollablePage { required property DcContext context required property DcAccountsEventEmitter eventEmitter - signal messagesChanged - onMessagesChanged: { - // Reload chatlist - updateChatlist(); - } + Connections { + target: chatlistPage.eventEmitter - signal messagesNoticed - onMessagesNoticed: { - // Reload chatlist - updateChatlist(); + function onMessagesChanged() { + // Reload chatlist + updateChatlist(); + } + function onMessagesNoticed() { + // Reload chatlist + updateChatlist(); + } } Component.onCompleted: { - eventEmitter.onMessagesChanged.connect(messagesChanged) - eventEmitter.onMessagesNoticed.connect(messagesNoticed) updateChatlist() } |