Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 2

Qt-interest Archive, May 2001
problem with XInitThreads


Message 1 in thread

Hello!

I have the following problem:
In my multithreaded app I call XInitThreads() first and then the app hangs
when I press any key. Without that call it works.

I made a short example program which shows this (attached). Just type
"make run". Then, in the dialog box, click in the edit line and try to
type anything. You should get the text correctly.

Next, in file main.cc uncomment the line with XInitThreads and try to do
the same (make run, click and type). The cursor in the edit line will stop
blinking when you press any key (at least it does in my computer) and
then you can do nothing.

I tested it on RedHat Linux 7, Qt 2.2.3 and 2.2.4 and XFree86 4.

Don't worry about the makefile, I just took it from the large app and that
is why it is so long.

regards

-- 
 [ signature omitted ] 

Attachment: xthread.tar.gz
Description: Binary data


Message 2 in thread

Hi,

In my multi-process application there is a one process written in QT
library. It is responsible for displaying various informations to the
user. There are many other processes in my application. they have to
send some data to the QT process.
I have completly no idea how to send the message to the at process  form
another process.
I do not think about threads, just a real processes created using fork().
Could anybody give me any solutions, please ?

Regards
Artur



Message 3 in thread

<offtopic>
I think the solution would be to use Unix's IPC message queue. 
You create a message queue (with msgget()) and then use it with msgsnd() 
in your "other" processes and msgrcv() in the QT one.
This solution is completely independant from QT library and it will
work only on System V compilants OSes...
</offtopic>
If you need some more information about how to use message queues, just
drop me a mail.

Czesc,
/M@ciek

On Fri, 25 May 2001 14:56:15 +0200 (CEST) Artur Downar wrote:

> Hi,
> 
> In my multi-process application there is a one process written in QT
> library. It is responsible for displaying various informations to the
> user. There are many other processes in my application. they have to
> send some data to the QT process.
> I have completly no idea how to send the message to the at process  form
> another process.
> I do not think about threads, just a real processes created using fork().
> Could anybody give me any solutions, please ?
> 
> Regards
> Artur
> 
> --
> List archive and information: http://qt-interest.trolltech.com


-- 
 [ signature omitted ] 

Message 4 in thread




> In my multithreaded app I call XInitThreads() first and then the app hangs
> when I press any key. Without that call it works.
> 

I dont know whether it is necessary to call XInitThreads() but without that call multithreaded programs written in Qt work fine.

regards


Message 5 in thread

On Wed, 9 May 2001, Jayan wrote:

> > In my multithreaded app I call XInitThreads() first and then the app hangs
> > when I press any key. Without that call it works.
> > 
> 
> I dont know whether it is necessary to call XInitThreads() but without
> that call multithreaded programs written in Qt work fine.

My program does not work fine. I have 5 pthreads. One of them (A) is
responsible for the user interface and is controlled by Qt. There is
another thread (B) which receives some data from network, disk or anything
else. This thread creates images from the received data and displays them
in a window created by Qt. It uses low-level X Window functions. But XFree
doesn't like it when A and B work with X in the same time, it just
crashes often.

I don't want to pass a message from B to A and then display the image
using the Qt thread, that would be only a workaround. X docs say that
XInitThreads should do the thing. And it does. The program is stable
except it has problems with the keyboard.

-- 
 [ signature omitted ] 

Message 6 in thread

Hi,

> I don't want to pass a message from B to A and then display the image
> using the Qt thread, that would be only a workaround. X docs say that
> XInitThreads should do the thing. And it does. The program is stable
> except it has problems with the keyboard.

Have a look at
	http://doc.trolltech.com/threads.html

Dimitri


Message 7 in thread

Hello

On Sat, 19 May 2001, Dimitri Papadopoulos wrote:

> > I took a look. And it seems that I do nothing wrong. I do not pass a
> 
> Are you aware that Qt functions must be called from a single thread?
> 
> > QWidget to another thread. I pass an X Window identifier. Qt procedures
> > are not being called concurrently. Only X Window procedures are. They are
> 
> So you're sure that you're calling Qt functions from within a single
> thread? I'm not sure I understand here. You're calling Qt from a single
> thread but you do call X11 functions from many threads? Why? Is this
> a Qt or a raw X11 program? Are the X window identifiers related to
> Qt windows?

More details: Qt functions are called only from a single Qt thread. This
thread creates some windows which are painted by another thread using
low-level X Window functions (XPutImage etc). I do this because this
thread captures images from a camera and it is important to display them
quickly.

But all these explanations are not so important since even much simpler
application does not work.

> > reentrant if I call XInitThreads. But Qt hates XInitThreads. It seems to
> > be a bug in Qt, since even a simple, single-thread app does not work with
> > XInitThreads.
> 
> Then this could be a bug in XInitThreads. Well, it could be a bug
> in Qt as well. But one can't tell without more details. Send the
> simple app to the list - not to me please. It's worth a thousand
> words.

So here it comes. It does almost nothing but shows enough.
All you have to do is:
- "make run" in an X terminal
- in a window click in a text edit
- press some keys - they should work

Now in main.cc uncomment the line with XInitThreads() and again:
- "make run" in an X terminal
- in a window click in a text edit
- press some keys - they should not work

Tested on Linux RedHat 7, Qt 2.2.3 and 2.2.4, XFree 4.

The only one important file is main.cc. dialog.ui is generated by
designer.

Don't be afraid of the large makefile and some auxiliary files. I took
them from another application. They are quite useful and it is enough to
modify "project" file to use it on your own.

regards

-- 
 [ signature omitted ] 

Attachment: xthread.tar.gz
Description: Binary data


Message 8 in thread

Hello everyone:
  I used to do thread programming with pthread package on UNIX and
CreateThread() system call on NT platform and now we are trying to write
our GUI display portion of our program with QT.  This is the questions.


  On UNIX platform, Is QT Thread class implemented using pthread
package?   No matter whether it is true or not, can we mix pthread
package function  calls like pthread_create_thread and QT Thread class
to create new threads?  In addition, we can use pthread_mutex call from
pthread package and QT mutex in the same program?


  On NT platform, Is QT thread class implemented using CreateThread()
system call?  No matter whether it is true or not, can we mix pthread
function call with QT Thread class to create new threads?  


Thanks


TCS


Message 9 in thread

Hello TC,

Monday, May 21, 2001, 7:19:13 AM, you wrote:

TS> Hello everyone:
TS>   I used to do thread programming with pthread package on UNIX and
TS> CreateThread() system call on NT platform and now we are trying to write
TS> our GUI display portion of our program with QT.  This is the questions.


TS>   On UNIX platform, Is QT Thread class implemented using pthread
TS> package?   No matter whether it is true or not, can we mix pthread
TS> package function  calls like pthread_create_thread and QT Thread class
TS> to create new threads?  In addition, we can use pthread_mutex call from
TS> pthread package and QT mutex in the same program?


TS>   On NT platform, Is QT thread class implemented using CreateThread()
TS> system call?  No matter whether it is true or not, can we mix pthread
TS> function call with QT Thread class to create new threads?  

TS> Thanks


TS> TCS

I think QT should call _beginthreadex() on Win32 using VC++,
otherwise it a is broken design.

-- 
 [ signature omitted ] 

Message 10 in thread

> Hello TC,
>
> Monday, May 21, 2001, 7:19:13 AM, you wrote:
>
> TS> Hello everyone:
> TS>   I used to do thread programming with pthread package on UNIX and
> TS> CreateThread() system call on NT platform and now we are trying to
write
> TS> our GUI display portion of our program with QT.  This is the
questions.
>
>
> TS>   On UNIX platform, Is QT Thread class implemented using pthread
> TS> package?   No matter whether it is true or not, can we mix pthread
> TS> package function  calls like pthread_create_thread and QT Thread class
> TS> to create new threads?  In addition, we can use pthread_mutex call
from
> TS> pthread package and QT mutex in the same program?
>
>
> TS>   On NT platform, Is QT thread class implemented using CreateThread()
> TS> system call?  No matter whether it is true or not, can we mix pthread
> TS> function call with QT Thread class to create new threads?
>
> TS> Thanks
>
>
> TS> TCS
>
> I think QT should call _beginthreadex() on Win32 using VC++,
> otherwise it a is broken design.
>
> --
> Best regards,
> David Xu
>
> --
> List archive and information: http://qt-interest.trolltech.com
>

It does use _beginthreadex() and friends.
Using QThread makes it possible to post events to the GUI thread. This is
not possible (or at least no as easy) when using pthread or Win32 native
threads.

--
 [ signature omitted ] 

Message 11 in thread

>
> It does use _beginthreadex() and friends.
> Using QThread makes it possible to post events to the GUI thread. This is
> not possible (or at least no as easy) when using pthread or Win32 native
> threads.

QThread::postEvent is a static method.  It is just as easy to call this
method from a QThread thread than a pthread thread.

-K