You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Friday, March 26th 2010, 12:44am

progress bar and cancel button

i have gui app that processes large data sets.

so i have a progress bar (QProgressBar) to show the progress of the processing and a cancel button to cancel the processing.

the problem is when the processing starts, the window stops responding. i can't click on the cancel button. i think this is because the processing and the window is in the same thread.

should i move the processing to a different thread? the reason i didn't do it is that its the processing method that updates the progress bar. as the progress bar is a gui item i don't want to access it outside the main thread.

any ideas?

thnx

2

Friday, March 26th 2010, 7:19am

That's why there are slots and signals.

Create a thread for the processing.
Make the thread emit signals of progress
Connect those signals to your GUI

3

Tuesday, March 30th 2010, 11:49pm

Create a thread for the processing.
Make the thread emit signals of progress
Connect those signals to your GUI

in signals and slots, is it possible for a signal to send objects?

for example,

Source code

1
2
signals:
    	void results(QList<MyClass>, QList<MyClass>);


and write

Source code

1
emit results(m1,m2);


i tried that and it won't work. but it works if i have standard types.

is it not possible to emit complex objects? also these lists are huge. is the size the problem?

4

Wednesday, March 31st 2010, 8:49am

is it not possible to emit complex objects? also these lists are huge. is the size the problem?


I use PyQt (python bindings) and this is easily possible.

For C++, you can take a look at http://qt.nokia.com/doc/4.6/qmetatype.html#details as suggested in this thread Signal and complex type

Good luck :)

5

Wednesday, March 31st 2010, 2:09pm

Why not let a QTimer to trigger the progressbar?

6

Wednesday, March 31st 2010, 2:34pm

Usually signals and slots do not require complex types, nor QTimer (!?!)

For a simple thing like a progressbar update, your thread will emit a Signal with an integer between 0 and 100.
In the slot, you get this integer and update the progressbar.
Check this out : http://hopf.chem.brandeis.edu/yanglingfa…ding/index.html



Now, if you want to show huge lists in the UI. It is not necessary to pass them in Signals. Your UI can have a reference to the thread and its class members.

You can do :
1. your thread builds the list (in a class member)
2. your thread emits "newItem" signal
3. in the slot "onNewItem", your UI accesses the threads attribute, and updates the widgets