Qt Forum

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

    Call for Presentations - Qt World Summit

    Unsolved How to create message box with customised buttons

    Mobile and Embedded
    2
    7
    2472
    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
      Sriu1 last edited by

      how to create message box with customized buttons , which also takes input from user and performs some action.

      1 Reply Last reply Reply Quote 0
      • sierdzio
        sierdzio Moderators last edited by

        It's all described in the docs: https://doc.qt.io/qt-5/qmessagebox.html#advanced-usage

        (Z(:^

        1 Reply Last reply Reply Quote 1
        • S
          Sriu1 last edited by

          Below is my code snippet, but im facing seg fault at messageBox.exec(), with this error "Problem creating accessible interface for: QLabel(0x7fffe0003aa0, name = "qt_msgbox_label") " , also im not executing the below code in qt context

          QMessageBox messageBox(QMessageBox::Question,
          tr("Critical Error"),
          tr("Exit the application"),
          QMessageBox::Yes | QMessageBox::No,
          NULL);
          messageBox.setButtonText(QMessageBox::Yes, tr("Yes"));
          messageBox.setButtonText(QMessageBox::No, tr("No"));
          if (messageBox.exec() == QMessageBox::No) {
            cout << " clicked no"<< endl;
          }
          
          sierdzio 1 Reply Last reply Reply Quote 0
          • sierdzio
            sierdzio Moderators @Sriu1 last edited by

            @Sriu1 said in How to create message box with customised buttons:

            im not executing the below code in qt context

            Can you elaborate on that?

            Do you have a QApplication defined in your app?

            (Z(:^

            1 Reply Last reply Reply Quote 0
            • S
              Sriu1 last edited by

              The above code is a part of C++ class, which inherits from QObject.
              I have also tried the below code snippet which you have suggested from : https://doc.qt.io/qt-5/qmessagebox.html#advanced-usage and face seg fault with the below error : "Problem creating accessible interface for: QPushButton(0x7fffe0003050)
              Make sure to deploy Qt with accessibility plugins.
              "

              QMessageBox msgBox;
              QPushButton *connectButton = msgBox.addButton(tr("Connect"), QMessageBox::ActionRole);
              QPushButton *abortButton = msgBox.addButton(QMessageBox::Abort);

              msgBox.exec();

              if (msgBox.clickedButton() == connectButton) {
              // connect
              } else if (msgBox.clickedButton() == abortButton) {
              // abort
              }

              sierdzio 1 Reply Last reply Reply Quote 0
              • sierdzio
                sierdzio Moderators @Sriu1 last edited by

                @Sriu1 said in How to create message box with customised buttons:

                The above code is a part of C++ class, which inherits from QObject.

                OK, but do you use QApplication in your app? QObject can't work without a QApplication instance.

                (Z(:^

                1 Reply Last reply Reply Quote 1
                • S
                  Sriu1 last edited by

                  Thanks for the input. I will try accordingly and get back.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post