[Qt-interest] Mainthread is busy though WorkerThread::run() is finished
Andre Somers
andre at familiesomers.nl
Tue Sep 1 12:28:32 CEST 2009
Santhosh Y wrote:
> Andre Somers wrote:
>> Santhosh Y wrote:
>>
>>> Hi,
>>>
>>> Please find the attached files with the mail.
>>>
>>> It is a compiling code.
>>>
>>> What I tried is the following:-
>>>
>>> 1. MainThread, holds the GUI elements
>>> 2. WorkerThread allots storage and adds to GUI element of MainThread
>>> * QTableWidgetItem setting into QTableWidget
>>>
>>>
>>> My qn here is that, once the workerThread finishes run()
>>> implementation, MainThread is still busy. How to solve this issue.
>>>
>>> In the code I attached, I hold QTableWidget on MainThread and I tried
>>> to set cell items of table in worker thread; But as soon as I finish
>>> adding cell items GUI has to be active.
>>> But in my case it is not responding.
>>>
>>>
>>> Please answer some body the reason for the above behavior.
>>>
>>>
>> Please READ the answers to your previous question.
>> You can do NO GUI RELATED THINGS from another thread. That includes
>> "adding to GUI elements" or changing QTableWidgetItems or adding them to
>> a QTableWidget. In worker threads, keep away from the GUI!
>>
>> André
>>
> Hi Andre,
>
> I was facing the issue I mentioned above, when I add 40000 items to
> the table but not in the case where I add 4,000 items
> In the later scenario, table shows the 4000 elements where as in
> former case, GUI is not responding.
>
>
Fine. So only add 4000 elements. Solved. Right?
What is the question you are asking here? Why the problem hits you if
you add 40k and not if you add 4k items? The whole point is that
touching the GUI from outside the main thread is unsupported. That means
that is sometimes may appear to work, but you can not rely on it.
*Anything* may change the situation from "works" to "crash" or something
in between. That includes, but is not limited to, the time of day, your
platform, your compiler version, your system load, your CPU brand, the
amount of memory installed, the lunar phase, the alignment of the
planets, prayers to the God of Computers, and, yes, the number of items
you add.
If you are doing GUI related things from outside the main thread, first
fix this. Just accept that that is NOT possible in Qt.
André
P.S.
> ----------------------------------------------------
> Y Santhosh Kumar
> Senior Software Engineer
> SoftJin Technologies Private Limited
I would have hoped a "Senior Software Engineer" would appreciate the
value of reading documentation and heeding advice of experienced users...
More information about the Qt-interest-old
mailing list