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. updating field in a modal dialog

updating field in a modal dialog

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 1.3k Views 2 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #1

    Hi all -

    I've added a modal QDialog to display a progress bar for a file transfer. Updates to the progress bar would come from the worker thread to the main UI widget via a signal. The UI widget would in turn signal the progress QDialog to update the progress bar.

    How do I display the progress QDialog without blocking the UI Dialog from receiving signals from the worker? Do I have to make the progress QDialog modeless?

    Thanks...

    JonBJ 1 Reply Last reply
    0
    • mzimmersM mzimmers

      Hi all -

      I've added a modal QDialog to display a progress bar for a file transfer. Updates to the progress bar would come from the worker thread to the main UI widget via a signal. The UI widget would in turn signal the progress QDialog to update the progress bar.

      How do I display the progress QDialog without blocking the UI Dialog from receiving signals from the worker? Do I have to make the progress QDialog modeless?

      Thanks...

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @mzimmers
      Does your "QDialog to display a progress bar" have any special "furniture" or other stuff on it you want requiting you to use your own QDialog, or could you use http://doc.qt.io/qt-5/qprogressdialog.html ? Because I think that shows example of using it modelessly, so it's written for you?

      1 Reply Last reply
      3
      • mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by
        #3

        The only thing I was displaying besides the actual progress bar was the filename being transferred.

        I think I discovered the problem: I was invoking the progress QDialog with an exec() call. I changed it to open() and it seems to perform as desired. But...now you have me interested in the QProgressDialog class. (I like that it has an active "cancel" button.)

        Here's what I'm trying:

            QProgressDialog qpd("Transferring file", "Abort Transfer", 0, 100, this);
            QObject::connect(this, &Widget::progressChanged, &qpd, &QProgressDialog::setValue);
            qpd.setAutoClose(false);
            qpd.exec();
        

        If I use the code as above, it blocks updates from the worker. If I change exec() to open(), it appears and immediately disappears. What might I be doing wrong? (I'm fine with this being a modal dialog.)

        Thanks.

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

          Hi,

          qpd is a local variable (on the stack), therefore as soon a s you reach the end of the function, it's destroyed. You have to allocate it on the heap. However you have to also ensure that you destroy it properly once you're done with it.

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

          mzimmersM 1 Reply Last reply
          2
          • SGaistS SGaist

            Hi,

            qpd is a local variable (on the stack), therefore as soon a s you reach the end of the function, it's destroyed. You have to allocate it on the heap. However you have to also ensure that you destroy it properly once you're done with it.

            mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on last edited by
            #5

            @SGaist got it...thanks.

            // in main.cpp
            QObject::connect(worker, &Worker::transferInProgress, widget, &Widget::updateProgress); 
             QObject::connect(worker, &Worker::transferComplete, widget, &Widget::deleteProgressDialog);
            ...
            // in widget.h
            void updateProgress(int progress) {emit progressChanged(progress);}
            ...
            // in widget.cpp
            void Widget::showFileTransfer()
            {
                m_fileTransferDialog = new QProgressDialog("Transferring file", "Abort Transfer", 0, 100, this);
                QObject::connect(this, &Widget::progressChanged, m_fileTransferDialog, &QProgressDialog::setValue);
                m_fileTransferDialog->open();
            }
            ...
            void Widget::deleteProgressDialog()
            {
                delete m_fileTransferDialog;
                QMessageBox qmb(QMessageBox::NoIcon,
                                "File Transfer Complete",
                                "The file transfer has completed.",
                                QMessageBox::Ok,
                                this);
                qmb.exec();
            }
            
            
            1 Reply Last reply
            1

            • Login

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