Oh, and don't forget to assign value to private ValueHolder valueHolder before first run, or you'll get NullPointerException.
On Wed, Sep 30, 2009 at 5:10 PM, Aekold Helbrass <[email protected]> wrote: > On Wed, Sep 30, 2009 at 4:52 PM, Dusan Zatkovsky <[email protected]> wrote: >> On Wednesday 30 of September 2009 15:43:13 Dusan Zatkovsky wrote: >> >> Maybe, what about following idea - start a thread with will repeatelly call >> QApplication.processEvents() in acceptable interval? Then I should do my job >> in main thread, show messageboxes etc... >> >> What do you think? > > No, I don't think it will work. And also amount of work will not be > much bigger than implementing something similar to SwingWorker. > > Idea of SwingWorker: > > private ValueHolder valueHolder; > private final Object valueLockObject = new Object(); > > // assume this is method where your operation begins: > private void mainMethod() { > QApplication.invokeLater(new WorkerClass()); > for (int i = 0; i < 666; i++) { > int v = 0; > // do you calculations here > valueHolder.setValue(v); > } > // to stop events sending: > valueHolder = null; > } > > private class ValueHolder { > > int value; > > public int getValue() { > return value; > } > > public void setValue(int value) { > this.value = value; > } > > } > > private class WorkerClass implements Runnable { > > public void run() { > ValueHolder _v; > synchronized (valueLockObject) { > if (valueHolder == null) { > return; > } > _v = valueHolder; > valueHolder = new ValueHolder(); > } > // set you progress bar value from here > // ... > > // and after you have it - put another executor into events loop: > QApplication.invokeLater(new WorkerClass()); > } > > } > -- Heresylabs code: http://heresylabs.googlecode.com/ Heresylabs blog: http://heresylabs.org/ _______________________________________________ Qt-jambi-interest mailing list [email protected] http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest
