I am making a QT application that updates a window based on information received from sockets. Here is how I did it:
configure a timer that forces the application to check sockets
after receiving new information (if any), I change the context data that is used when drawing the widget and forwarding the call to it
Naturally, my code I need is a drawing event
However, I ran into a problem. The application is unstable and will accidentally crash (usually after sending to the socket it started). When debugging, the stack trace shows that it crashes in the depths of QT itself, while distributing - I believe, judging by the stack - another drawing event.
How can I prevent this? Maybe if you do not redraw, if the drawing is not done yet?
Code that processes the receipt of new data; dt.listen () returns the number of items changed.
void CommandPanel::update()
{
static int udel = 0;
udel += 1+dt.listen();
if ( udel > 40)
{
this->repaint();
udel = 0;
}
}
Code Associating It With A Timer
//object T that is derived from QWidget is created
QTimer timer;
QObject::connect(&timer, SIGNAL(timeout()), &T, SLOT(update()));
timer.start(1000 / 10);
T.show();
When debugging I reciever, a segmentation error signal occurs when I come to the line with '!!!' in the comment. Here is a complete stack trace.
Topic 3 (Thread 0xb75b9b70 (LWP 9183)): _ # 0 0x0012e416 in __kernel_vsyscall () There is no information about the character table.
_ # 1 0x00e49834 at pthread_cond_timedwait @@ GLIBC_2.3.2 () from / lib / i 386-linux-gnu / libpthread.so.0 There is no information about the symbol table.
_ # 2 0x01472f0e in ?? () from / usr / lib / i 386-linux-gnu / libgthread-2.0.so.0 There is no information about the symbol table.
_ # 3 0x0114042c in ?? () from / lib / i 386-linux-gnu / libglib-2.0.so.0 There is no information about the symbol table.
_ # 4 0x01140f6d in g_async_queue_timed_pop () from / lib / i 386-linux-gnu / libglib-2.0.so.0 There is no information about the symbol table.
_ # 5 0x01198980 in??() /lib/i 386-linux-gnu/libglib-2.0.so.0
.
_ # 6 0x011962df in??() /lib/i 386-linux-gnu/libglib-2.0.so.0
.
_ # 7 0x00e44e99 start_thread() /lib/i 386-linux-gnu/libpthread.so.0
.
_ # 8 0x0105573e () /lib/i 386-linux-gnu/libc.so.6
.
Thread 2 (Thread 0xb7dbab70 (LWP 9072)):
_ # 0 0x0012e416 __kernel_vsyscall()
.
_ # 1 0x01046f76 () /lib/i 386-linux-gnu/libc.so.6
.
_ # 2 0x0117d84b g_poll() /lib/i 386-linux-gnu/libglib-2.0.so.0
.
_ # 3 0x0116d1af in??() /lib/i 386-linux-gnu/libglib-2.0.so.0
.
_ # 4 0x0116d92b g_main_loop_run() /lib/i 386-linux-gnu/libglib-2.0.so.0
.
_ # 5 0x0166b304 in??() /usr/lib/i 386-linux-gnu/libgio-2.0.so.0
.
_ # 6 0x011962df ??() /lib/i 386-linux-gnu/libglib-2.0.so.0
.
_ # 7 0x00e44e99 start_thread() /lib/i 386-linux-gnu/libpthread.so.0
.
_ # 8 0x0105573e () /lib/i 386-linux-gnu/libc.so.6
.
1 (Thread 0xb7fe4710 (LWP 8938)):
_ # 0 0x00d183f8 QMetaObject:: activate (QObject *, QMetaObject const *, int, void **)() /usr/lib/libQtCore.so.4
.
_ # 1 0x00d652f7 QTimer:: timeout()() /usr/lib/libQtCore.so.4
.
_ # 2 0x00d1e3ee QTimer:: timerEvent (QTimerEvent *)() /usr/lib/libQtCore.so.4
.
_ # 3 0x00d17214 QObject:: event (QEvent *)() /usr/lib/libQtCore.so.4
.
_ # 4 0x0025cd24 QApplicationPrivate:: notify_helper (QObject *, QEvent *)() /usr/lib/libQtGui.so.4
.
_ # 5 0x002618ce QApplication:: notify (QObject *, QEvent *)() /usr/lib/libQtGui.so.4
.
_ # 6 0x00d020bb QCoreApplication:: notifyInternal (QObject *, QEvent *)() /usr/lib/libQtCore.so.4
.
_ # 7 0x00d321e4 in??() /usr/lib/libQtCore.so.4
.
_ # 8 0x00d2ee27 in??() /usr/lib/libQtCore.so.4
.
_ # 9 0x0116caa8 g_main_context_dispatch() /lib/i 386-linux-gnu/libglib-2.0.so.0
.
_ # 10 0x0116d270 in??() /lib/i 386-linux-gnu/libglib-2.0.so.0
.
_ # 11 0x0116d524 g_main_context_iteration() /lib/i 386-linux-gnu/libglib-2.0.so.0
.
_ # 12 0x00d2f53c QEventDispatcherGlib:: processEvents (QFlags)() /usr/lib/libQtCore.so.4
.
_ # 13 0x00310775 in??() /usr/lib/libQtGui.so.4
.
_ # 14 0x00d01289 QEventLoop:: processEvents (QFlags)() /usr/lib/libQtCore.so.4
.
_ # 15 0x00d01522 QEventLoop:: exec (QFlags)() /usr/lib/libQtCore.so.4
.
_ # 16 0x00d05ecc QCoreApplication:: exec()() /usr/lib/libQtCore.so.4
.
_ # 17 0x0025a8e7 QApplication:: exec()() /usr/lib/libQtGui.so.4
.
_ # 18 0x0804ac19 main (argc = 1, argv = 0xbffff8a4) .. /wargui/main.cpp: 40
app = <incomplete type>
timer = <incomplete type>
T = {<QLabel> = {<No data fields>}, view = 0x10e33c0, dt = {qflag = 0, channelSockets = {0x8566108 "/tmp/channel1", 0x8567788 "/tmp/channel2", 0x8565298 "/tmp/channel3", 0x8565330 "/tmp/channel4", 0x8567db8 "/tmp/channel5", 0x8567e00 "/tmp/channel6", 0x8567108 "/tmp/channel7"}, mesSources = {0x8567e78, 0x85653a0, 0x85652b0, 0x8565348, 0x8567dd0, 0x85670d8, 0x8567120}, cossock = 33, chansocks = {26, 27, 28, 29, 30, 31, 32}, logLength = {0, 0, 0, 0, 0, 0, 0, 1, 1}, logs = {0x8568620, 0x8568788, 0x85688f0, 0x8568a58, 0x8568bc0, 0x8568d28, 0x8568e90, 0x8568ff8, 0x8569160}, targets = 0x85651e0}}
pm = <incomplete type>
r = -1073743880
.
qt , , . , , qt, update().