Qt World Summit: Register Today!

Add button to QMessageBox with some conditions?

  • Hi,
    I have a QMessageBox in which I added a QPushbutton by ::addButton().
    The clicked() SIGNAL of the push button is connected as per my requirement to other objects.
    The problem is that whenever the button is clicked the message box gets closed.
    I have tried every combination of Role with that button, but every time the messagebox gets closed.

    The message box displays a count down, hence I am not running it by the conventional method of ::exec().
    The following code shows how I am running the message:

    @QMessageBox msg;
    QString constText = "This is constant\n";
    QString timeText = "";
    for(int i = count; i >= 0; i--)
    msg.setText(constText + timeText);
    MyThreadSleep(QThread::currentThread(), 1000);//Current thread is slept for approximately 1 sec

    Any idea how I can add the button without it affecting the messageBox?

  • Moderators

    i don't see any addButton() code in your example. I don't really understand what you want to achieve.

    Also i would suggest using QTimer over than your thread-approach for the countdown.

  • Lifetime Qt Champion


    To add to raven-worx, a QMessageBox is not meant to be used for a "permanent" dialog like that. You should subclass QDialog instead

Log in to reply