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. Add button to QMessageBox with some conditions?
Forum Updated to NodeBB v4.3 + New Features

Add button to QMessageBox with some conditions?

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

    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 = "";
    msg.show();
    for(int i = count; i >= 0; i--)
    {
    timeText.setNum(i);
    msg.setText(constText + timeText);
    QApplication::processEvents();
    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?

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      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.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

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

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        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