Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Dialog box with Proceed and Cancel buttons

    General and Desktop
    2
    4
    76
    Loading More Posts
    • 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
      stretchthebits last edited by stretchthebits

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • S
          stretchthebits last edited by

          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 Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            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 Reply Quote 0
            • First post
              Last post