Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Best way QDialog should communicate with MainWindow?
Qt 6.11 is out! See what's new in the release blog

Best way QDialog should communicate with MainWindow?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 599 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    WhatIf
    wrote on last edited by
    #1

    Hello,

    I have a QDialog with 2 buttons. One button performs an operation and the other is a cancel button. The button the performs an operation, emits a signal then closes the dialog.

    I want to know which of the two buttons was clicked when the QDialog closes and control returns to MainWindow. I read in other posts that the QDialog should not be messing with variable created in its parent, MainWindow.

    Thank you

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chrisw01
      wrote on last edited by
      #2

      Hi, I believe the Cancel button returns QDialog::Rejected; I recommend that you have your other button do its stuff then call accept(); Thus returning either QDialog::Accepted or QDialog::Rejected.

      So in your code you could do as

      result = dialog.exec();
      

      Then result will either be Accepted or Rejected depending on the button pressed.

      1 Reply Last reply
      3
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #3

        QDialog::Accept and QDialog::Reject are the built-in result types, as @Chrisw01 mentioned.
        If you want more customized options you can use any integer value with done(). Create a public enum in your dialog class with the options and then connect your buttons to slots that call done() with that enum values.
        A user of your dialog can then call exec() and inspect the return value by comparing it to the enum values.

        1 Reply Last reply
        2

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved