1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
Item { property string text; Text { ... } MouseArea { onClicked: { if (parent.text === "Quit") { Qt.quit() } else if (parent.text === "Start") { globalObject.start() } else if (parent.text === "Stop") { globalObject.stop() } } } } |
I don’t always understand why people do things in some ways.
Rookie mistakes
What ways?
The way shown in the code above, where one event handler seems to handle three (or two) buttons and even uses hardcoded text strings to identify the function to execute.
Breaks if someone translates the UI, breaks if someone changes Quit to Close or Exit, and is not good separation of responsibility as it combines (in the same code block) starting/stopping something within the running application with application termination
Because they really don’t know better.