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. Missing function entry in QMessageBox documentation
Forum Updated to NodeBB v4.3 + New Features

Missing function entry in QMessageBox documentation

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 2.4k 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.
  • B Offline
    B Offline
    Binary91
    wrote on last edited by
    #1

    Hi,

    I was wondering about the fact that I can't find a function called "setButtonText(QStandardButton, const QString &)" in Qt's documentation of QMessageBox.
    In fact, this function exists and works great, so maybe there is some update missing in the documentation?!

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      "setButtonText":http://qt-project.org/doc/qt-5/qmessagebox-obsolete.html#setButtonText is obsolete in Qt 5 and so probably missing.

      157

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Binary91
        wrote on last edited by
        #3

        Oh, well that could be the solution. But I'm wondering why this functionallity is obsolete in Qt 5, because I don't know an easier way to change the text of a QStandardButton, do you?

        1 Reply Last reply
        0
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          Hi,

          [quote author="Binary91" date="1415541360"]Oh, well that could be the solution. But I'm wondering why this functionallity is obsolete in Qt 5, because I don't know an easier way to change the text of a QStandardButton, do you?[/quote]I think the idea is this: It's better to set the correct text at initialization, rather than setting one text first and then changing it later.

          The button text can be set through the QMessageBox constructor, or through addButton(). So, setButtonText() is not needed anymore.

          Can you think of a use-case where these functions are not suitable?

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0
          • B Offline
            B Offline
            Binary91
            wrote on last edited by
            #5

            [quote]The button text can be set through the QMessageBox constructor[/quote]Hm... maybe I'm not able to see it, but which constructor of QMessageBox accepts QStrings related to the text of its StandardButtons?

            I see only two constructors there:
            "QMessageBox(QWidget *)
            QMessageBox(Icon, const QString &, const QString &, StandardButtons, QWidget *, Qt::WindowFlags)"

            Maybe I don't get it...

            1 Reply Last reply
            0
            • JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by
              #6

              Sorry, my mistake -- there's no constructor that lets you specify custom text.

              Use QMessageBox::addButton().

              @
              QMessageBox b2(QMessageBox::NoIcon,
              "My Title",
              "My Text");
              b2.addButton("My OK", QMessageBox::AcceptRole);
              b2.addButton("My Cancel", QMessageBox::RejectRole);
              @

              By the way, you cannot change the text of a standard button. setButtonText() only works on custom buttons.

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              0
              • B Offline
                B Offline
                Binary91
                wrote on last edited by
                #7

                Yeah, this would be the second way I think, but then, on my mind, the setButtonText() method is not that obsolete..

                [quote]By the way, you cannot change the text of a standard button. setButtonText() only works on custom buttons.[/quote]That's weird, because it works fine for me:
                @QMessageBox *msgbox = new QMessageBox(QMessageBox::Question, "my message", "Does it work?", QMessageBox::Yes | QMessageBox::No);
                msgbox->setButtonText(QMessageBox::Yes, "YeahYeahYeah");
                msgbox->setButtonText(QMessageBox::No, "Oh noooo");@

                Did you try that on your system and it failed? That would be interesting I think...

                1 Reply Last reply
                0
                • JKSHJ Offline
                  JKSHJ Offline
                  JKSH
                  Moderators
                  wrote on last edited by
                  #8

                  Ah, I see. I misunderstood how to use that function.

                  The function takes an integer as the first argument...
                  @
                  void setButtonText(int button, const QString & text)
                  @

                  ...so I gave it a button index...
                  @
                  QMessageBox msgbox(QMessageBox::NoIcon, "My Message", "Click Something!", QMessageBox::Ok | QMessageBox::Cancel);
                  msgbox.setButtonText(0, "Click Me!");
                  msgbox.setButtonText(1, "Go Away!");
                  @

                  ...which didn't work.

                  Anyway, I think I know why the Qt devs deprecated these functions. The old API is ambiguous and inconsistent. See http://qt-project.org/doc/qt-5/qmessagebox-obsolete.html

                  • The first version of QMessageBox::information() takes int arguments, where we're supposed to provide a QMessageBox::StandardButton value
                  • The second version of QMessageBox::information() also takes int arguments, but we're supposed to provide button index numbers.

                  By just looking at the function signature, it is not obvious whether I should provide a button index value or a StandardButton value.

                  To remove this ambiguity, all the QMessageBox functions which take int arguments (including setButtonText()) are now deprecated.

                  Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                  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