[solved]messagebox in qt



  • 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.



  • 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());
    @



  • 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



  • 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.



  • sam

    Exactly this is what I wanted.
    Thanks



  • You are welcome!!!!

    Kindly Edit your title and prepend [Solved] .

    Happy Coding !!!



  • 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();
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.