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. [solved]messagebox in qt
QtWS25 Last Chance

[solved]messagebox in qt

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 9.1k 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
    sandy.pareek
    wrote on 13 Jul 2012, 18:50 last edited by
    #1

    hello.

    I want my messagebox to print integer values , i am able to do it with string vals, bt not with integer.
    any help in this regard is appreciated.
    Thnks.

    this is what i been doing
    @
    int i1=10;
    QMessageBox msgBox;
    msgBox.addButton(QMessageBox::Yes);
    msgBox.addButton(QMessageBox::No);
    msgBox.setText("MESSAGE BOX");
    msgbox.exec();
    //I want to print i1 value into messagebox, I read somwhere, + sign is used, but how exactly? is there any other way out?//
    @
    It throws error when I use it the way we do so in java or in turbo c++ programming.

    "my code, my life"

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vezprog
      wrote on 13 Jul 2012, 19:12 last edited by
      #2

      Heres what I do.

      @
      int integerValue = 10;
      QMessageBox yesNoMsgBox;
      yesNoMsgBox.setWindowTitle("Title of window");
      yesNoMsgBox.setText("Text you want to show up");
      yesNoMsgBox.setInformativeText(QString("Informative text below the main text with value ").append(QVariant(integerval).toString()));
      yesNoMsgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
      yesNoMsgBox.setDefaultButton(QMessageBox::Cancel);
      switch (yesNoMsgBox.exec()){
      case QMessageBox::Yes: {
      break;
      }
      case QMessageBox::No: {
      break;
      }
      case QMessageBox::Cancel: {
      break;
      }
      }
      @

      EDIT: As for the + comment, I didnt see this before. You are able to append strings together with the + sign so the same thing can be done like this as well:
      @
      yesNoMsgBox.setInformativeText("Informative text below the main text with value " + QVariant(integerval).toString());
      @

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sandy.pareek
        wrote on 13 Jul 2012, 19:35 last edited by
        #3

        dvez43
        Thanks dude. Your tweaking helped me. I guess i am right when i say it uses append method after string text.
        I wanted to show up only integer values so i just kept that
        @
        yesNoMsgBox.setInformativeText(QString("Informative text below the main text with value ").append(QVariant(integerval).toString()));
        @
        informative text line blank which showed only integer value.
        Thanks

        "my code, my life"

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Sam
          wrote on 14 Jul 2012, 07:27 last edited by
          #4

          One more approach can be like:

          @int i1 =10;
          QMessageBox msgBox;
          msgBox.addButton(QMessageBox::Yes);
          msgBox.addButton(QMessageBox::No);
          msgBox.setText("Message Box " +QString::number(i1) );
          msgBox.exec();@

          Check if this is your requirement.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sandy.pareek
            wrote on 14 Jul 2012, 07:55 last edited by
            #5

            sam

            Exactly this is what I wanted.
            Thanks

            "my code, my life"

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Sam
              wrote on 14 Jul 2012, 08:03 last edited by
              #6

              You are welcome!!!!

              Kindly Edit your title and prepend [Solved] .

              Happy Coding !!!

              1 Reply Last reply
              0
              • H Offline
                H Offline
                Hesam_GL
                wrote on 14 Jul 2012, 08:13 last edited by
                #7

                There is still a very simple way to do this :

                @ int i1 =10;
                QMessageBox msgBox;
                msgBox.addButton(QMessageBox::Yes);
                msgBox.addButton(QMessageBox::No);
                msgBox.setText(QString("Message Box %1").arg(i1));
                msgBox.exec();
                @

                1 Reply Last reply
                0

                5/7

                14 Jul 2012, 07:55

                • Login

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