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

Qt-interest Archive, July 2007
Badlength X error, while painting widget in qt


Message 1 in thread

hi everybody,

my simple qt code is like this...


void* fun(void *d)
{
while(1)
{
	fm->imgForm();
	
}


}
void Form1::focusInEvent(QFocusEvent *e)
{
pthread_t tid;
pthread_create(&tid,NULL,&fun,NULL);

}

void Form1::imgForm()
{
	    fm->setPaletteBackgroundPixmap(QPixmap("/root/a.jpg"));
}



In the above my simple code, i am setting image a.jpg from thread to form. fm 
is a form object. when i run this program, it works fine for sometimes, but 
sometimes it will give run time error like

X error: Badlength(poly request too large or xlib length error)....

and my application stucks..... 


Can anyone have a solution, plz tell me.......this error is frustating me...

I am using qt-3.1 with Fedora 6.

Thanks and Regards,
Niranjan

--
 [ signature omitted ] 

Message 2 in thread

On 07.07.07 11:55:07, Niranjan wrote:
> hi everybody,
> 
> my simple qt code is like this...
> 
> 
> void* fun(void *d)
> {
> while(1)
> {
> 	fm->imgForm();
> 	
> }
> 
> 
> }
> void Form1::focusInEvent(QFocusEvent *e)
> {
> pthread_t tid;
> pthread_create(&tid,NULL,&fun,NULL);
> 
> }
> 
> void Form1::imgForm()
> {
> 	    fm->setPaletteBackgroundPixmap(QPixmap("/root/a.jpg"));
> }
> 
> 
> 
> In the above my simple code, i am setting image a.jpg from thread to form. fm 
> is a form object. when i run this program, it works fine for sometimes, but 
> sometimes it will give run time error like

You're simply lucky that it works the first runs, executing GUI stuff
rom a non-GUI thread doesn't work in Qt. Also Qt already has a
thread-class that hides the platform specific stuff from the application
and is more portable than pthreads, I suggest to use it.

Andreas

-- 
 [ signature omitted ] 

Message 3 in thread

hi,
Thanks for your response..

ok, u mean using QThread instead of pthread it is possible to paint widget 
without any problem.... or is there any solution to paint widget from non-gui 
thread...

Thanks and Regards,
Niranjan

On Saturday 07 July 2007 13:00, Andreas Pakulat wrote:
> On 07.07.07 11:55:07, Niranjan wrote:
> > hi everybody,
> >
> > my simple qt code is like this...
> >
> >
> > void* fun(void *d)
> > {
> > while(1)
> > {
> > 	fm->imgForm();
> >
> > }
> >
> >
> > }
> > void Form1::focusInEvent(QFocusEvent *e)
> > {
> > pthread_t tid;
> > pthread_create(&tid,NULL,&fun,NULL);
> >
> > }
> >
> > void Form1::imgForm()
> > {
> > 	    fm->setPaletteBackgroundPixmap(QPixmap("/root/a.jpg"));
> > }
> >
> >
> >
> > In the above my simple code, i am setting image a.jpg from thread to
> > form. fm is a form object. when i run this program, it works fine for
> > sometimes, but sometimes it will give run time error like
>
> You're simply lucky that it works the first runs, executing GUI stuff
> rom a non-GUI thread doesn't work in Qt. Also Qt already has a
> thread-class that hides the platform specific stuff from the application
> and is more portable than pthreads, I suggest to use it.
>
> Andreas

--
 [ signature omitted ] 

Message 4 in thread

On 07.07.07 15:02:08, Niranjan wrote:
> hi,
> Thanks for your response..
> 
> ok, u mean using QThread instead of pthread it is possible to paint widget 
> without any problem.... or is there any solution to paint widget from non-gui 
> thread...

Yes, the solution is called queued signals or posting events. You can't
draw directly from a non-gui thread, thats why its called non-gui.

Andreas

-- 
 [ signature omitted ]