Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

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

    General and Desktop
    qmessegebox
    3
    5
    1950
    Loading More Posts
    • 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
      ForestPoem last edited by

      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 Reply Quote 0
      • kshegunov
        kshegunov Moderators last edited by

        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 Reply Quote 0
        • D
          Devopia53 last edited by

          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 Reply Quote 0
          • F
            ForestPoem @Devopia53 last edited by

            @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 Reply Quote 0
            • D
              Devopia53 @ForestPoem last edited by

              @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 Reply Quote 0
              • First post
                Last post