[Qt-interest] Button text not updated when enabled from a pthread

K. Frank kfrank29.c at gmail.com
Tue Sep 27 05:38:51 CEST 2011


Hello Venu!

On Mon, Sep 26, 2011 at 11:12 PM, venugopal reddy <venu.forum at gmail.com> wrote:
> Hi,
>  I have situation where I need to enable or disable some buttons in a
> pthread. [we get a call back from another library, where the call back
> implemented with pthreads]
> any one faced this problem, is there any way to solve this problem.

Yes.  The issue is that only the gui thread (typically the main thread)
may manipulate the gui in a Qt application.

The standard way to handle this in Qt is to have your callback function
(running in a callback thread that you don't control, and that is different
from the main gui thread) send a signal to an object that runs in (more
precisely, has thread affinity for) the main gui thread.

So, for example, your "pthread" thread emits a "disableButton" signal
that is connected to the "setDisabled" slot of your QButton object.  The
QButton "runs in" the gui thread (unless you've done something perverse).

> -Venu

Good luck.


K. Frank



More information about the Qt-interest-old mailing list