Support request #265

QProgressDialog does not pop up anymore.

Added by bruce oy almost 2 years ago. Updated over 1 year ago.

Status:NewStart date:20.02.2013
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:-
Target version:-
Resolution: Affected Jambi version:4.8.x
Junior Job:No Affected Java version:Oracle 1.7

Description

at first, QProgressDialog will pop up and after finishing the search, QProgressDialog auto close itself. but after clicking the find button several times, QProgressDialog will not pop up but the search is still on progress.
os : openSUSE12.2
KDE: 4.10
QT : qt4-4.8.4
qtjambi: libqtjambi-snapshot-0.0.0.git.1342764136-14.1.i586
my sample application : FindFiles.java, see attachments.
this application will search those files which contains specified text.

to arise the error information, you should run my code, input file name pattern, text to search, directory to search.

FindFiles.java Magnifier (8.11 KB) bruce oy, 20.02.2013 05:46

History

#1 Updated by bruce oy almost 2 years ago

it seems i have to call QProgressDialog.show() manually.
the following code works well:

    private List<String> findFiles(QDir directory, List<String> files,
            String text) {
        QProgressDialog progressDialog = new QProgressDialog(this);
        progressDialog.setAutoClose(false);
        progressDialog.setAutoReset(false);
        progressDialog.setCancelButtonText(tr("&Cancel"));
        progressDialog.setRange(0, files.size() - 1);
        progressDialog.setWindowTitle(tr("Find Files"));

        List<String> foundFiles = new LinkedList<String>();

        for (int i = 0; i < files.size(); ++i) {
            progressDialog.setValue(i);
            progressDialog.setLabelText(tr("Searching file number " + i
                    + " of " + files.size() + "..."));
            progressDialog.show();
            QApplication.processEvents();

            if (i == progressDialog.maximum()) {
                progressDialog.close();
                QApplication.processEvents();
            }

            if (progressDialog.wasCanceled())
                break;

            QFile file = new QFile(directory.absoluteFilePath(files.get(i)));

            if (file.open(QIODevice.OpenModeFlag.ReadOnly)) {
                String line = "";
                QTextStream in = new QTextStream(file);
                while (!in.atEnd()) {
                    if (progressDialog.wasCanceled())
                        break;
                    line = in.readLine();
                    if (line.contains(text)) {
                        foundFiles.add(files.get(i));
                        break;
                    }
                }
            }
            file.close();
        }
        return foundFiles;
    }

#2 Updated by Darryl Miles almost 2 years ago

Yes I would guess it is possible to get out of sync.

The use of 'QApplication.processEvents();' is to ensure the UI eventloop gets to run to update the UI because there is slow file processing in the main GUI thread.

Can you confirm if the problem is solved now ?

Are you saying the example needs improving ? I have not compared the file to the original example yet. Yes looks like you have other changes, can you confirm if the original demo/example works ok ?

I would also put the call to QProgressDialog.show(); after 'progressDialog.setWindowTitle(tr("Find Files"));' and before 'for (int i = 0; i < files.size(); ++i) {' so it is not in the loop.

I would also put the close() code outside the for(;;) loop just before turn, so the dialog stays on screen even if max calculations are wrong, also no need for the "if(i == processDialog.maximum())" test when it is moved.

#3 Updated by bruce oy almost 2 years ago

Darryl Miles wrote:

Yes I would guess it is possible to get out of sync.

The use of 'QApplication.processEvents();' is to ensure the UI eventloop gets to run to update the UI because there is slow file processing in the main GUI thread.

Can you confirm if the problem is solved now ?

after i modified my code according to your suggestions(move out QProgressDialog.show() and close()), QProgressDialog pop up,although not fast enough, maybe i should put file processing into another thread.

Are you saying the example needs improving ?

no, i am thinking maybe there is a bug in event processing, just indicated in my original example.

I have not compared the file to the original example yet. Yes looks like you have >other changes, can you confirm if the original demo/example works ok ?

original demo/example works not ok.

#4 Updated by Darryl Miles over 1 year ago

  • Tracker changed from Bug to Support request

Are you sure your file processing does not occur too fast for you to visually see the pop up ?

If the slow file processing is being done in the main GUI thread it is necessary to ensure to manually allow the event loop to run. IIRC my quick look at the example does show that processEvents() is called at the appropriate point to ensure the dialog can be displayed.

It is also necessary to call it if you want any % value update to indicate on screen and also when it is closed to make it disappear.

You should add some logging to stdout with timestamps. You need to prove at what relative timestamp in milli/nano-seconds. You should also add some Thread#sleep() calls to make your slow operations even slower to verify that is the ask does 10% every second the dialog always appears and always updates and always takes at least 19 seconds to complete.

If you prove all these things then from my point of view the code is working as expected and the issue here is your understanding of Qt and how events processing works.

If it is still not working (from your perspective) then after making the above modifications please re-attach new *.java file implementing it.

Also available in: Atom PDF