PDA

View Full Version : emit is slow in Thread?



vishal.chauhan
2nd August 2007, 07:13
Hi All,
I m using Qt 4.1.5 on my MAC.

I have a thread from which I m emitting some signal to Gui thread.

But this emit works fine if I add some small no of Item in treeWidget But if I add suppose 10000 item in treeWidget and emit a signal for each item than the process get very slow infact if thread has completed its work in 20 sec then after 1 and 1/2 min the gui thread complete its work and the process also look like hang in that time period.


So if somebody knows the issue then plz help me out.

Thanks.

marcel
2nd August 2007, 09:29
Don't emit 10000 signals. Of course it will be slow, because the GUI event handler will have to handle 10000 events.

Instead emit fewer signals, but containing more data.
F.e. emit 100 signals that each add 100 items to the widget. Probably you will have to cache the item data.
Still, there will be a delay, but the application will be more responsive.

Regards

vishal.chauhan
2nd August 2007, 09:45
OK.

I will try this.

I want to ask one more thing that can I take a return value from the emit signal because I want this QTreeWidgetItem pointer to be added in the list which is in thread.

marcel
2nd August 2007, 09:52
OK.

I will try this.

I want to ask one more thing that can I take a return value from the emit signal because I want this QTreeWidgetItem pointer to be added in the list which is in thread.

No, you can't have a return value for a signal./ This is mainly because you don't actually implement the signals. You just declare them. The "implementation" is done by moc.



because I want this QTreeWidgetItem pointer to be added in the list which is in thread

Create a small class or struct that has a few members(public, nothing fancy).
You emit the signal with this an instance of this class as parameter. In the worker thread, before you emit, populate the class with the needed data( the tree item, and whatever you may need in the GUI thread, when you receive the signal ).

Be careful that when emitting signals with custom types, these types have to be registered with Qt.

See qRegisterMetaType.

Regards