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. Beyond accept() reject()

Beyond accept() reject()

Scheduled Pinned Locked Moved General and Desktop
6 Posts 5 Posters 1.5k Views
  • 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.
  • J Offline
    J Offline
    jocala
    wrote on last edited by
    #1

    I have a dialog that includes an array of buttons that I want to trigger various actions. How can the program that calls the dialog determine exactly which button was pressed? Ideally, I'd like any button press to close the dialog and then drop into something similar to a switch/case : button1, do this, button2, do that, button3 do the other... Right now one button is linked to accept() and another to reject(), which is kind of limiting.

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

      Accept is an indication that "some" action is to be taken, while reject means the user wants to cancel or "escape" from the dialog/decision entirely.
      Having said that all the buttons that "do something" should accept and set some flag to indicate which action was chosen.
      You could then check if the dialog was accepted, and if so, enter a switch/case to test the flag and decide which action to take.
      Either that or emit custom signals from the buttons clicks.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        thEClaw
        wrote on last edited by
        #3

        Maybe you can make use of "finished()":http://doc.qt.io/qt-5/qdialog.html#finished instead of accepted()/rejected(). Just connect your buttons clicked()-signals to a short lambda (or a normal slot, should you want to avoid that) and you should be fine. A custom enum might be be a good idea, though.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jocala
          wrote on last edited by
          #4

          Got it, thanks. Each button when clicked assigns a value to my return code; each button except for my cancel is connected to the accept() slot. Seems to work fine :)

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            You might also be interested by the "QDialogButtonBox":http://doc.qt.io/qt-5/qdialogbuttonbox.html class

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              Also note that you can still access your dialog class after the user has made his choice. That means that you can also provide API on it to read any value you need.

              1 Reply Last reply
              0

              • Login

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