[Qt-interest] Accessing GUI elements from a 'C' callback function
Malyushytsky, Alex
alex at wai.com
Wed Oct 7 23:21:19 CEST 2009
>> Also it is not a GUI thread to update the GUi element.
It has to be done by GUI thread.
All you need to do is notify the GUI thread that slider has to be updated.
You may to it in multiple ways, but it has to be done thread safe.
For example you can call postEvent from function called from your function to notify that slider has to be repainted.
Or create instance of QObject derived class, define custom signal it will emit when you need an update.
Connect this signal to whatever slot you want to be called to update slider (repaint() /update()) using Queued connection.
Add function to this class which emits this signal.
Call this function from your C function.
Make sure you don't use this instance in the gui or other threads for other purposes (or make such usage thread safe).
According to my understanding this should work.
Regards,
Alex
-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Anil H
Sent: Wednesday, October 07, 2009 1:14 AM
To: qt-interest; qt-embedded-interest
Subject: [Qt-interest] Accessing GUI elements from a 'C' callback function
All,
I am using qt 4.5.2 on x86-linux.
I am using qt slider widget as a seek bar in a media player application.
The seek bar(progress of the movie) has to be moved after a callback
is recieved.
But the callback function is a 'C' function and is called from a
thread created internal to a C library . Hence GUI elements can't be
accessed in this callback function.
I tried out giving static member functions of mainwindow class as a
callback function to C library. Callback handle as pointer to
mainwindow object(this pointer).
But when i try to access GUI elements in the static member function,
it gives out segmentation fault .
Also it is not a GUI thread to update the GUi element.
Is there any alternate solution to this issue of accessing GUI
elements from a 'C' callback function ?. Or how to accesss GUI
elements from a C callback function in a non-gui thread?
Thanks & regards
Anil H
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest
---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.
"This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you."
"Please consider our environment before printing this email."
More information about the Qt-interest-old
mailing list