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

Qt-interest Archive, July 2007
Badlength X error: poly request too large or xlib length error


Message 1 in thread

hi everybody,


I am having the problem with my qt code.

I am updating gui widget in thread(pthread). As from some forums , i observed 
that, this error comes when u update the gui widget in a thread.... 

so, i used customevent to send event from thread to gui slot when i need to 
update widget, but the problem still not solved...

Can anyone have a idea , what's the solution of this problem.....

Thanks and Regards,
Niranjan 

--
 [ signature omitted ] 

Message 2 in thread

Niranjan schrieb:
> hi everybody,
> ..
> so, i used customevent to send event from thread to gui slot when i need to 
> update widget, but the problem still not solved...

Is this Qt 4? The preferred solution would be to use /asynchronous/ 
signals (aka queued signals in "Qt speak"). The worker thread needs to 
have a running event queue though. To make sure set the 5th parameter in 
the connect() call explicitly to Qt::QueuedConnection.

Qt tries to auto-detect what you want when you set it to 
Qt::AutoConnection which is the default value, but this can be a bit 
tricky depending on when exactly you emit the signals; if the sender and 
receiver are /associated/ to *different* threads (see QObject::thread()) 
then a queued connection (signal delivery) will be made, else a direct 
connection (signal delivery) will be made.

If you really want to use custom events (as was the way it had to be 
done in Qt 3) make sure you use QCoreApplication::postEvent (which is 
thread-safe) and *not* QCoreApplication::sendEvent.

Why? Because the event handler of the receiver would still be called 
within the calling thread (with sendEvent()), that is the worker thread, 
and this is forbidden.

postEvent() on the other hand "queues" the event into the Qt event queue 
which is running in the main thread. When the event handler of the 
receiver is eventually called from within the Qt event loop this is in 
the context of the main (aka GUI) thread - which is exactly what you 
want here.

Cheers, Oliver

--
 [ signature omitted ] 

Message 3 in thread

hi,
thanks for your quick response,

i am using qt-3.1 with Fedora 6 linux.

I used customevent in thread like this

ScreenChangeEvent ce(1) = new ScreenChangeEvent(blue);
QApplication::sendEvent(fm,&ce);

ScreenChangeEvent is  my user defined class, i receive event in like


void mainForm::customEvent( QCustomEvent *e )
{
  	fm->setPaletteBackgroundPixmap(QPixmap("/root/a.jpg"));   
}



Suppose i used postEvent instead of sendEvent, does my problem will solve????

If possible, can u give me one example???



Thanks and Regards,
Niranjan



On Tuesday 10 July 2007 22:05, Till Oliver Knoll wrote:
> Niranjan schrieb:
> > hi everybody,
> > ..
> > so, i used customevent to send event from thread to gui slot when i need
> > to update widget, but the problem still not solved...
>
> Is this Qt 4? The preferred solution would be to use /asynchronous/
> signals (aka queued signals in "Qt speak"). The worker thread needs to
> have a running event queue though. To make sure set the 5th parameter in
> the connect() call explicitly to Qt::QueuedConnection.
>
> Qt tries to auto-detect what you want when you set it to
> Qt::AutoConnection which is the default value, but this can be a bit
> tricky depending on when exactly you emit the signals; if the sender and
> receiver are /associated/ to *different* threads (see QObject::thread())
> then a queued connection (signal delivery) will be made, else a direct
> connection (signal delivery) will be made.
>
> If you really want to use custom events (as was the way it had to be
> done in Qt 3) make sure you use QCoreApplication::postEvent (which is
> thread-safe) and *not* QCoreApplication::sendEvent.
>
> Why? Because the event handler of the receiver would still be called
> within the calling thread (with sendEvent()), that is the worker thread,
> and this is forbidden.
>
> postEvent() on the other hand "queues" the event into the Qt event queue
> which is running in the main thread. When the event handler of the
> receiver is eventually called from within the Qt event loop this is in
> the context of the main (aka GUI) thread - which is exactly what you
> want here.
>
> Cheers, Oliver
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body. List archive and information:
> http://lists.trolltech.com/qt-interest/

--
 [ signature omitted ] 

Message 4 in thread

Niranjan wrote:
> hi,
> thanks for your quick response,
> 
> i am using qt-3.1 with Fedora 6 linux.

Especially with threaded programming, you might save yourself quite a
bit of fuss by updating to qt4 now. I think a recent qt4 should build
fine on fc6. That way you avoid having to port your app to qt4 later.

--
 [ signature omitted ] 

Message 5 in thread

Niranjan schrieb:
> ...
> Suppose i used postEvent instead of sendEvent, does my problem will solve????

Did you understand my previous posting? If so, you should understand by 
now that this indeed solves your problem.

> 
> If possible, can u give me one example???

Why don't you try it out by yourself by simply replacing the one line

   QApplication::sendEvent(fm,&ce);

by

   QApplication::postEvent(fm,&ce);

?

Is this the "example" you were looking for? ;)

Cheers, Oliver

--
 [ signature omitted ] 

Message 6 in thread

hi,

Thank you, I tested my code, and its working fine using postEvent instead of 
sendevent....  

I am sending the event in a thread, like

QCustomEvent *e=new QCustomEvent(10000);
QApplication::postEvent(fm,&e);

As i am not deleting  e (deallocating memory of e), because when i use

delete e

in a custom event slot,it will give me segmentation fault....

Now i am not deleting e, and its working ok without any problem....

But as i am creating object of QCustomEvent, in a thread everytime when i 
paint widget.... can u tell me plz...will it give me problem in a future as i 
am not deallocating memory....


Thanks and Regards,
Niranjan. 
 


On Wednesday 11 July 2007 20:18, Till Oliver Knoll wrote:
> Niranjan schrieb:
> > ...
> > Suppose i used postEvent instead of sendEvent, does my problem will
> > solve????
>
> Did you understand my previous posting? If so, you should understand by
> now that this indeed solves your problem.
>
> > If possible, can u give me one example???
>
> Why don't you try it out by yourself by simply replacing the one line
>
>    QApplication::sendEvent(fm,&ce);
>
> by
>
>    QApplication::postEvent(fm,&ce);
>
> ?
>
> Is this the "example" you were looking for? ;)
>
> Cheers, Oliver
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body. List archive and information:
> http://lists.trolltech.com/qt-interest/

--
 [ signature omitted ]