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. QMessagebox I would like to know how the three seconds shut down.

QMessagebox I would like to know how the three seconds shut down.

Scheduled Pinned Locked Moved Unsolved General and Desktop
qmessegebox
5 Posts 3 Posters 2.8k 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.
  • F Offline
    F Offline
    ForestPoem
    wrote on last edited by
    #1

    QMessageBox* msgBox = new QMessageBox(QMessageBox::Information,
    "This is the title",
    "OK Button Result",
    QMessageBox::Ok, this,
    Qt::FramelessWindowHint);
    msgBox->setInformativeText("-Wait ");
    msgBox->exec();

    my qmessagebox
    how to After 3 seconds Shutdown

    1 Reply Last reply
    0
    • kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      You can't, not with this code anyway. You could create a modeless dialog (QMessageBox is a QDialog subclass), meaning you call msgBox-show() instead of msgBox->exec() and start a single-shot timer for 3 seconds, that has its timeout() signal connected to the slot you want to use for shutdown (i.e. if shutdown means just hiding the message box, you either connect it to hide() or deleteLater(), depending on your particular needs). Bear in mind that while the modeless message box will not block the program, you might need to deal with the case of losing focus - the user clicking on your main window/widget etc.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Devopia53
        wrote on last edited by
        #3

        You can use the following: use the modal dialog...

        QMessageBox msgBox(QMessageBox::Information,
        "This is the title",
        "OK Button Result",
        QMessageBox::Ok, this,
        Qt::FramelessWindowHint);
        msgBox.setInformativeText("-Wait ");

        QTimer timer; // Don't use QTimer::singleShot()
        timer.setSingleShot(true);
        connect(&timer, &QTimer::timeout, [&]{ msgBox.close(); }); // with c++11
        timer.start(3000);

        msgBox.exec();

        F 1 Reply Last reply
        0
        • D Devopia53

          You can use the following: use the modal dialog...

          QMessageBox msgBox(QMessageBox::Information,
          "This is the title",
          "OK Button Result",
          QMessageBox::Ok, this,
          Qt::FramelessWindowHint);
          msgBox.setInformativeText("-Wait ");

          QTimer timer; // Don't use QTimer::singleShot()
          timer.setSingleShot(true);
          connect(&timer, &QTimer::timeout, [&]{ msgBox.close(); }); // with c++11
          timer.start(3000);

          msgBox.exec();

          F Offline
          F Offline
          ForestPoem
          wrote on last edited by
          #4

          @Devopia53

          source code dump is error

          error: 'void QTimer::timeout()' is protected

          error: within this context

          error: no matching function for call to 'class::connect(QTimer*, void (QTimer::)(), class::class(QWidget)::<lambda()>)'

          D 1 Reply Last reply
          0
          • F ForestPoem

            @Devopia53

            source code dump is error

            error: 'void QTimer::timeout()' is protected

            error: within this context

            error: no matching function for call to 'class::connect(QTimer*, void (QTimer::)(), class::class(QWidget)::<lambda()>)'

            D Offline
            D Offline
            Devopia53
            wrote on last edited by
            #5

            @ForestPoem

            If your compiler does not support C++11 lambda expressions, you can use following:

            connect(&timer, &QTimer::timeout, &msgBox, &QMessageBox::close);

            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