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. Dialog box with Proceed and Cancel buttons

Dialog box with Proceed and Cancel buttons

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 630 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.
  • S Offline
    S Offline
    stretchthebits
    wrote on last edited by stretchthebits
    #1

    I have created my own dialog box.

    class CWarningDialog : public QDialog
    

    I have also created a couple of buttons, ok and cancel, via code

    QPushButton	*BUTTONProcess;   //This is like a Ok button
    QPushButton	*BUTTONCancel;
    

    Under MFC, I gave the Proceed button the ID of IDOK and Cancel is IDCANCEL.
    So, when Proceed or Cancel is pressed, I get an integer returned by the DoModal() member function.

    What is the Qt equivalent code to this?

    //MFC version
    int returnVal;
    returnVal=adlg_WarningDialog.DoModal();
    if(returnVal==IDCANCEL)
    {
    }
    
    //My Qt equivalent code
    int returnVal;
    returnVal=adlg_WarningDialog.exec();
    if(returnVal)
    {
    }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      See QDialog::DialogCode.

      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
      • S Offline
        S Offline
        stretchthebits
        wrote on last edited by
        #3

        I got it working.

        void CWarningDialog::OnButtonProceed()
        {
        	accept();
        }
        
        void CWarningDialog::OnButtonCancel()
        {
        	reject();
        }
        

        and in my main window code

        int returnVal;
        returnVal=adlg_WarningDialog.exec();
        if(returnVal==QDialog::Rejected)
        {
        }
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          These two custom slots are overkill. You can directly connect your buttons to the appropriate accept/reject slots.

          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

          • Login

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