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. show QDialog when called from QMessageBox
QtWS25 Last Chance

show QDialog when called from QMessageBox

Scheduled Pinned Locked Moved Unsolved General and Desktop
qmessageboxqdialog
5 Posts 2 Posters 2.5k 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.
  • T Offline
    T Offline
    the_
    wrote on 23 Mar 2016, 12:23 last edited by
    #1

    Hi all

    What is the correct method to show and update a QProgressDialog that is shown when I execute a slot from a QMessageBox?

    For example I have a QMessageBox that looks like this:

    QMessageBox::warning(this,"Logout Warning","All data will be deleted. Continue?",QMessageBox::Yes,QMessageBox::No);
    

    If Yes is clicked, a slot is executed that deletes all data (delete rows from a database).
    I want to show the progress in a QDialog with ProgressBar and close the QDialog when removing is finished, but neither QDialog::show() nor QDialog::open() do what I expect. It does open and close the dialog, but I it seems the dialog is frozen.

    If i call QDialog::exec() the dialog is shown and i also see the ProgressBar, but its not updated (as expected because of blocking until closed).

    -- No support in PM --

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 23 Mar 2016, 13:20 last edited by
      #2

      How do you update the progress bar in the dialogue?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      T 1 Reply Last reply 23 Mar 2016, 13:29
      0
      • J jsulm
        23 Mar 2016, 13:20

        How do you update the progress bar in the dialogue?

        T Offline
        T Offline
        the_
        wrote on 23 Mar 2016, 13:29 last edited by the_
        #3

        @jsulm

        //in header file
        QProgressbar *pbar;
        QDialog *dialog;
        
        //in constructor
        dialog = new QDialog;
        pbar = new QProgressbar;
        pbar->setMinimum(0);
        QVBoxLayout *v = new QVBoxLayout(dialog);
        v->addWidget(new QLabel("deleting...");
        v->addWidget(pbar);
        
        //after clicking QMessageBox::Yes
        pbar->setMaximum(list.count());
        pbar->setValue(0);
        dialog->show(); // or dialog->open()? or what ever is correct to let me see the content of the dialog ;)
        //list is a QList<int>
        foreach(int x,list) {
          q.bindValue(":id",x);
          q.exec();
          pbar->setValue(pbar->value()++);
        }
        dialog->hide();
        

        -- No support in PM --

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 23 Mar 2016, 13:34 last edited by
          #4

          I don't really understand your code.
          You show a dialog when the user clicks Yes button, but the progress bar is not part of that dialog?
          What is q?
          Your foreach loop blocks the event loop, so the progress bar will not be updated before the loop ends.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          T 1 Reply Last reply 23 Mar 2016, 13:38
          0
          • J jsulm
            23 Mar 2016, 13:34

            I don't really understand your code.
            You show a dialog when the user clicks Yes button, but the progress bar is not part of that dialog?
            What is q?
            Your foreach loop blocks the event loop, so the progress bar will not be updated before the loop ends.

            T Offline
            T Offline
            the_
            wrote on 23 Mar 2016, 13:38 last edited by
            #5

            @jsulm

            pbar is in the VBoxLayout of the dialog, q is a QSqlQuery.

            I Just modified the code so that the dialog also contains the yes and no buttons and no QMessageBox is shown. When i now show the QDialog instead of the QMessageBox and then execute the slot, everything looks good and the progressbar is updated at each step of the foreach() loop.

            -- No support in PM --

            1 Reply Last reply
            0

            1/5

            23 Mar 2016, 12:23

            • Login

            • Login or register to search.
            1 out of 5
            • First post
              1/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved