PDA

View Full Version : Fast updation for controls in QT3



soumyadeep_pan
4th September 2008, 11:48
I am using QT 3.3 for my application and updating near about 150 line edit boxes. The rate of updation is twice in a second, and this updation will continue for more than 30 minutes which showing some problems like -

X Error: BadRequest (invalid request code or no such operation) 1
Major opcode: 255
Minor opcode: 0
Resource id: 0x40035e



MyApplication: Fatal IO error: client killed

There is no delay between the updation of 2 line edits.

Thanks in advance.

jacek
4th September 2008, 21:39
Do you use threads?

soumyadeep_pan
6th September 2008, 10:24
Yes I'm using pthread, I'm passing the main window object (which having 150 line edits) to the thread, and updating the line edits from the threads.

I have tried using QThread, which also showing the same issue.

jacek
6th September 2008, 15:12
Read this carefully: http://doc.trolltech.com/3.3/threads.html

Especially the part that says you can't touch the GUI from a non-GUI thread.

soumyadeep_pan
8th September 2008, 09:02
I tried with the QThread also, which is not working. I am uploading the sample program, that I have done using QThread. Thanks in Advance .....

jacek
8th September 2008, 15:04
Could you repeat my previous post with your own words?

soumyadeep_pan
11th September 2008, 07:34
Thanks a lot for that the XLib problems are not coming for QThread. But a new problems arise, if I'm using (for the samples I've attached in my previous post) QThread the main window is not coming properly (It's getting hanged), in the document also I could not get any solution for this, can anybody help me ?

jacek
12th September 2008, 02:29
if I'm using (for the samples I've attached in my previous post) QThread the main window is not coming properly
You can't mix threads and GUI.

soumyadeep_pan
12th September 2008, 10:44
To my orginal problem, can I do parallel GUI updation in QT ? Is there any way to do parallel processing with continuous parallel updation GUI in QT? thanks in advance .

jacek
12th September 2008, 22:52
To my orginal problem, can I do parallel GUI updation in QT ? Is there any way to do parallel processing with continuous parallel updation GUI in QT?
You would know that if you read that document I've pointed you to. You can use threads for processing, but only the main thread can do anything with the GUI.

soumyadeep_pan
13th September 2008, 05:27
only the main thread can do anything with the GUI.
:confused: What do you mean by a main thread ? Can I do any semaphore post to that thread ?

jacek
13th September 2008, 16:09
What do you mean by a main thread ?
The main thread (a.k.a. the GUI thread) is the one that created the QApplication instance.


Can I do any semaphore post to that thread ?
Typical way of communication between worker threads and the GUI thread is to use custom events. QApplication provides some locking mechanism, but custom events are better.

soumyadeep_pan
15th September 2008, 05:51
The main thread (a.k.a. the GUI thread) is the one that created the QApplication instance.


As I'm creating QApplication instance in main(), so I have to update in that thread (a.k.a Inside main() or any called functions from main()), but to my orginal problem I have to update some controls continuosly, as the following -

main ()
{
QApplication object;

while (1)
{
//Updation for the controls.
}

object.exec();
}

I assume this algorithm will successfully update controls, but it will be always in while loop and I'll not get any events from the other controls available in the same window. If I'm correct, can anybody suggest a solution for this ? ..thanks in advance ....

jacek
15th September 2008, 22:07
Use QTimer to fire a slot at given interval. You don't have to update faster than people can see.

soumyadeep_pan
19th September 2008, 10:23
:) ..Thanks a lot for your suggestion. Actually in my application I had nearly 15 pthread, which are updating the GUI, which was the main problem.
I want to know further is it possible to emit signals from pthreads ? I'have tried but it's showing segmentation fault. Thnaks .......

jacek
19th September 2008, 22:33
Actually in my application I had nearly 15 pthread, which are updating the GUI, which was the main problem.
Do you have 15 or more cores in your machine? If not, all those threads just make your application slower.


I want to know further is it possible to emit signals from pthreads ? I'have tried but it's showing segmentation fault.
What did you do exactly? You have to use a queued connection.

soumyadeep_pan
22nd September 2008, 06:06
Do you have 15 or more cores in your machine? If not, all those threads just make your application slower.


What did you do exactly? You have to use a queued connection.

These many number of threads simply for updation of few controls (512 edit boxes X 4Panles) which is not required at all, so I'm going to remove of all those threads. I want to keep one single pthread which will do all the calcultation in my application and after completing the calculations, it will emits a signal to a slot for controls updation. will it be ok ? If it is correct, then how I can emit a signal from pthread to slot (I already done this in a sample that creating seg fault) ? thanks in advance .........

jacek
28th September 2008, 22:51
will it be ok ?
It should be.


If it is correct, then how I can emit a signal from pthread to slot (I already done this in a sample that creating seg fault) ?
Make sure you use a queued connection. Do you have to use a pthread instead of QThread? Also could you post that sample program?

soumyadeep_pan
30th September 2008, 06:02
I am not familiar with the queued connection, I would like to go through this and implement as a queued connection. But, here's the code that creating the seg fault while I'm trying to post any event to SLOT. Thanks in Advance .....