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. QProgressDialog doubt

QProgressDialog doubt

Scheduled Pinned Locked Moved General and Desktop
24 Posts 5 Posters 19.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.
  • F Offline
    F Offline
    ferrazrafael
    wrote on last edited by
    #1

    Im needing to use a endless progressbar, because I dont know when my program will end, and later close it. I try this if this code:
    @
    QProgressDialog ProgressDialog("Processing","Cancel", 0,0, this);
    ProgressDialog.setWindowModality(Qt::WindowModal);
    ProgressDialog.setValue(0);
    MyFunction();
    ProgressDialog.close();
    @

    But the dialog doesnt show... what I need to do?

    thanks

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alexman
      wrote on last edited by
      #2

      Call qApp->processEvents(); into function MyFunction(); because of progress bar is used in one thread with calculation.

      1 Reply Last reply
      0
      • F Offline
        F Offline
        ferrazrafael
        wrote on last edited by
        #3

        How I do access qApp inside a QMainWindow? Im insisde of my MainWindow....

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DenisKormalev
          wrote on last edited by
          #4

          Maybe show() is forgotten for ProgressDialog ? And alexman is right about processEvents(). qApp is accessible everywhere, it is pointer to current running QApplication.

          1 Reply Last reply
          0
          • F Offline
            F Offline
            ferrazrafael
            wrote on last edited by
            #5

            Im receiving some errors trying to pass qApp pointer to other class of the function that I use.

            Says that "unexpect token 'const'"

            here is my function declaration:

            @
            void BalancedMerge_Multipath::Sort(const char *sFileName, uint32_t uKeyQuantity,
            uint32_t uMemorySize,
            uint32_t uBufferSize, QApplication *qApp)
            @

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DenisKormalev
              wrote on last edited by
              #6

              Can you say why do you want to pass it? It is available everywhere where you have QApplication header included

              1 Reply Last reply
              0
              • F Offline
                F Offline
                ferrazrafael
                wrote on last edited by
                #7

                [quote author="Denis Kormalev" date="1287947743"]Can you say why do you want to pass it? It is available everywhere where you have QApplication header included[/quote]

                Hummm, didnt know that this was possible.

                Ok I put qApp->processEvents() in some loops of my function. But nothing happens... any tip?

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  DenisKormalev
                  wrote on last edited by
                  #8

                  Maybe you can show some code? It will help me and others to find the problem.

                  1 Reply Last reply
                  0
                  • F Offline
                    F Offline
                    ferrazrafael
                    wrote on last edited by
                    #9

                    @
                    ProgressDialog.setWindowModality(Qt::WindowModal);
                    ProgressDialog.setMinimumDuration(0);;
                    ProgressDialog.setValue(0);
                    ProgressDialog.setRange(0,0);
                    if(ui->radioButton_isMultipath->isChecked())
                    {
                    BalancedMerge_Multipath balancedMerge_Multipath;
                    time(&initialTime); // Start Timer
                    balancedMerge_Multipath.Sort(ui->lineEdit_File_BalancedMerge->text().toStdString().c_str(),uFileSize, uMemorySize, ui->spinBox_BufferSize_BalancedMerge->value());
                    time(&finalTime); // Stop Timer
                    }
                    @
                    Inside balancedMerge_Multipath.Sort() I call qApp.processEvents()..

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      DenisKormalev
                      wrote on last edited by
                      #10

                      Again, what about show()ing dialog?

                      1 Reply Last reply
                      0
                      • F Offline
                        F Offline
                        ferrazrafael
                        wrote on last edited by
                        #11

                        show(), shows the dialog, but it doesnt have a progressbar or something, just stay there freezed.

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          goetz
                          wrote on last edited by
                          #12

                          bq. "From the API docs of QProgressDialog":http://doc.trolltech.com/main-snapshot/qprogressdialog.html#details
                          A common problem with progress dialogs is that it is difficult to know when to use them; operations take different amounts of time on different hardware. QProgressDialog offers a solution to this problem: it estimates the time the operation will take (based on time for steps), and only shows itself if that estimate is beyond minimumDuration() (4 seconds by default).

                          As you set the range from 0 to 0 the dialog assumes there is nothing to do and does not show up. You must set a reasonable range and call setValue() regularly to make the dialog visible.

                          http://www.catb.org/~esr/faqs/smart-questions.html

                          1 Reply Last reply
                          0
                          • F Offline
                            F Offline
                            ferrazrafael
                            wrote on last edited by
                            #13

                            Yes.. but I dont know when or how much steps I will do.. this is because I use setRange(0,0) so it just show a busy indicator.

                            1 Reply Last reply
                            0
                            • G Offline
                              G Offline
                              goetz
                              wrote on last edited by
                              #14

                              If you set the range from 0 to 0 there is obviously no work to be done, so the dialog will never show up.

                              I'd try this:
                              @
                              progress->setWindowModality(Qt::WindowModal);
                              progress->setLabelText("Please wait...");
                              progress->setRange(0,10);
                              // always show the dialog
                              // do no assumed time calculation
                              progress->setMinimumDuration(0);
                              // disable the cancel button at all
                              progress->setCancelButton(0);
                              // eventually show the dialog
                              progress->setValue(1);
                              @

                              http://www.catb.org/~esr/faqs/smart-questions.html

                              1 Reply Last reply
                              0
                              • D Offline
                                D Offline
                                dasmoeh
                                wrote on last edited by
                                #15

                                You can use exec to show your dialog. But it works only for me if i use a new Thread for my function. I'm looking for a solution without threads, but can't find something.

                                @
                                QProgressDialog dlg("Running...", QString(), 0, 0, this, Qt::CustomizeWindowHint | Qt::WindowTitleHint);
                                dlg.setRange(0,0);
                                MyThread* work = new MyThread();
                                connect(work, SIGNAL(statusText(QString)), &dlg, SLOT(setLabelText(QString)));
                                connect(work, SIGNAL(finished()), &dlg, SLOT(cancel()));
                                connect(work, SIGNAL(errorText(QString,QWaitCondition*)), this, SLOT(workError(QString,QWaitCondition*)));
                                work->start();
                                dlg.exec();
                                @

                                1 Reply Last reply
                                0
                                • D Offline
                                  D Offline
                                  DenisKormalev
                                  wrote on last edited by
                                  #16

                                  Use single @ tag before and after code. I've fixed it in this comment, but don't forget about it in future posts.

                                  What do you mean by "solution without threads"?

                                  1 Reply Last reply
                                  0
                                  • G Offline
                                    G Offline
                                    goetz
                                    wrote on last edited by
                                    #17

                                    If you do your work in the main thread, then that thread is blocked with your work. You want to process the pending events from time to time, eg. with "QCoreApplication::processEvents() ":http://doc.qt.nokia.com/4.7/qcoreapplication.html#processEvents

                                    If you do the work in a separate thread, the main thread's event loop continues to run and everything is updated automatically.

                                    http://www.catb.org/~esr/faqs/smart-questions.html

                                    1 Reply Last reply
                                    0
                                    • D Offline
                                      D Offline
                                      dasmoeh
                                      wrote on last edited by
                                      #18

                                      As long as i am waiting for a TIMEOUT
                                      @
                                      _tcpSocket.waitForConnected(TIMEOUT)
                                      @
                                      i want to show the QProgressDialog.

                                      Something like
                                      @
                                      QProgressDialog dlg("Running...", QString(), 0, 0, this, Qt::CustomizeWindowHint | Qt::WindowTitleHint);
                                      dlg.setRange(0,0);
                                      //dlg.exec()
                                      _tcpSocket.waitForConnected(TIMEOUT)
                                      dlg.cancel()
                                      @
                                      but if i use exec only the ProgressBar is running forever.

                                      Thank u for helping with the code tag. Hope its better now.

                                      1 Reply Last reply
                                      0
                                      • G Offline
                                        G Offline
                                        goetz
                                        wrote on last edited by
                                        #19

                                        this snippet works for me:

                                        @
                                        QProgressDialog pd;
                                        pd.setLabelText("waiting for connect");

                                        pd.setWindowModality(Qt::WindowModal);
                                        pd.setRange(0,0);
                                        // always show the dialog
                                        // do no assumed time calculation
                                        pd.setMinimumDuration(0);
                                        // disable the cancel button at all
                                        pd.setCancelButton(0);
                                        // eventually show the dialog
                                        pd.setValue(1);

                                        QTcpSocket sock;
                                        connect(&_tcpScoket, SIGNAL(connected()), &pd, SLOT(cancel()));
                                        _tcpScoket.connectToHost("host", 80);
                                        _tcpScoket.waitForConnected(30000);
                                        @

                                        Be aware that there is no need to explicitly exec the progress dialog (in contrary to an "ordinary" QDialog).

                                        http://www.catb.org/~esr/faqs/smart-questions.html

                                        1 Reply Last reply
                                        0
                                        • D Offline
                                          D Offline
                                          dasmoeh
                                          wrote on last edited by
                                          #20

                                          @Volker: Thank you. With processEvents() i can get the dialog visible. But it doesn't show title or progressbar. Only blank window. Some time ago i tried to put the tcpsocket in another thread, but it wasn't easy so it remained in the main thread. Is there a way to start the progressdialog in a new thread?

                                          edit: Just seen your answer. I will try it.

                                          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