II have created my own yes-no popup dialog (because QtQuick2 doesn't have one) and I would like to ask if the code I made can be improved. I am asking because I am new in QML and I have the suspicion that I didn't engineer a good solution. So I would like your opinions.

This is the YesNoMsg.qml , that contains the popup:

Qt Code:
  1. import QtQuick 2.7
  2. import QtQuick.Controls 2.0
  3.  
  4. Popup {
  5. id: yesno_msg_popup
  6. property string question
  7. signal yesno_yes_pressed()
  8. signal yesno_no_pressed()
  9.  
  10. Column {
  11. Label {
  12. id: yesno_msg_popup_title
  13. text: question
  14. }
  15. Text {
  16. id: yesno_msg_popup_text
  17. }
  18. Row {
  19. Button {
  20. id: yesno_msg_popup_yes_btn
  21. text: "Yes"
  22. onClicked: {
  23. yesno_msg_popup.close()
  24. yesno_msg_popup.yesno_yes_pressed()
  25. }
  26. }
  27. Button {
  28. id: yesno_msg_popup_no_btn
  29. text: "No"
  30. onClicked: {
  31. yesno_msg_popup.close()
  32. yesno_msg_popup.yesno_no_pressed()
  33. }
  34. }
  35. }
  36. }
  37.  
  38. }
To copy to clipboard, switch view to plain text mode 


And this is the code where I am using it:

Qt Code:
  1. Button {
  2. text: "test dialog"
  3. onClicked: {
  4. yes_no_msg.question="yes or no?"
  5. yes_no_msg.open()
  6. yes_no_msg.yesno_yes_pressed.connect(yes)
  7. yes_no_msg.yesno_no_pressed.connect(no)
  8. }
  9. function yes() {
  10. console.log("yes")
  11. yes_no_msg.yesno_yes_pressed.disconnect(yes)
  12. yes_no_msg.yesno_no_pressed.disconnect(no)
  13. }
  14. function no() {
  15. console.log("no");
  16. yes_no_msg.yesno_yes_pressed.disconnect(yes)
  17. yes_no_msg.yesno_no_pressed.disconnect(no)
  18. }
  19. }
  20. YesNoMsg {
  21. id: yes_no_msg
  22. }
To copy to clipboard, switch view to plain text mode 

As you can see, I have to connect() and disconnect() everytime I use the yesno dialog and this is not very comfortable thing to do.