c++ - Qt Creator crashes when using multiple threads -



c++ - Qt Creator crashes when using multiple threads -

i'm writing qt (5.3) programme has joystick test ui in it, need separate thread infinite while loop looking joystick axis/button value changes through sdl. part of code working fine can have thread qdebug() messages , seems work. main window, when seek open test joystick ui, programme crashes. i've had test joystick ui running separation without joystickthread thread , seems open fine.

the error messages inconsistent though - times, get

the programme has unexpectedly finished. /home/narendran/qtworkspace/build-linkcontrol-desktop-debug/linkcontrol crashed

this has shown once:

qxcbwindow: unhandled client message: "_gtk_load_iconthemes"

and few other times:

[xcb] unknown sequence number while processing queue [xcb] multi-threaded client , xinitthreads has not been called [xcb] aborting, sorry that. star: ../../src/xcb_io.c:274: poll_for_event: assertion `!xcb_xlib_threads_sequence_lost' failed.

i found mutual if xinitthreads(); not run in main function, on there, crashes same error(s).

main.cpp

class="lang-cpp prettyprint-override">#include <qsplashscreen.h> #include "linkcontrol.h" #include "configure.h" #include <unistd.h> #include <qapplication> #include <qpixmap> #include <qstyle> #include <qdesktopwidget> #include "linkports.h" #include "joystickthread.h" #include <x11/xlib.h> int main(int argc, char *argv[]) { xinitthreads(); qapplication a(argc, argv); qpixmap pix(":splash.png"); qsplashscreen splash(pix); splash.show(); a.processevents(); joystickthread jsthread; jsthread.start(); linkcontrol linkcontrol; usleep(1000000); splash.finish(&linkcontrol); usleep(100000); linkcontrol.show(); linkcontrol.setgeometry(qstyle::alignedrect(qt::lefttoright, qt::aligncenter,linkcontrol.size(),a.desktop()->availablegeometry())); homecoming a.exec(); }

the actual thread in joystickthread.cpp

class="lang-cpp prettyprint-override">#include "joystickthread.h" #include "global.h" #include "unistd.h" /* joystickthread::joystickthread(int _interval) { this->interval_us = _interval; } */ void joystickthread::run() { while(1) { if(joystick->connected) { joystick->updatejsdata(); // check changed values for(int i=0; i<joystick->axis.count(); i++) { if(joystick->axis.value(i) != joystick->axis_last[i]) { joystick->axisupdateemit(i); // qdebug() << "axis: " << << "\tvalue: " << joystick->axis.value(i); } joystick->axis_last[i] = joystick->axis.value(i); } for(int i=0; i<joystick->button.count(); i++) { if(joystick->button.value(i) != joystick->button_last[i]) { joystick->btnupdateemit(i); // qdebug() << "button: " << << "\tvalue: " << joystick->button.value(i); } joystick->button_last[i] = joystick->button.value(i); } } usleep(2500); } }

the function causes programme crash in linkcontrol.cpp

class="lang-cpp prettyprint-override">void linkcontrol::on_actionjoystick_test_triggered() { qdebug() << "starting check"; if(!js_test->initialized) { qdebug() << "not init"; js_test = new testjoystick(); js_test->initialized = true; qdebug() << "fininsh init"; } if(joystick->connected) { qdebug() << "showing ui"; js_test->show(); } else { qmessagebox::critical(this, tr("no joystick connected!"), tr("please connect joystick first...")); } }

where js_test declared testjoystick object in linkcontrol.h file

class="lang-cpp prettyprint-override">public: explicit linkcontrol(qwidget *parent = 0); qslider *portsliders[16]; qlineedit *setvals[16]; serialterminal *ser_term; testjoystick *js_test; ~linkcontrol();

thank much! please allow me know if need anymore information.

qthreads little tricky used initially, , have share of gotchas.

you should build , connect appropriate items @ top of run function.

if other places, need create sure don't utilize qt::autoconnection, instead utilize qt:queuedconnection.

http://qt-project.org/doc/qt-5/qt.html#connectiontype-enum

certain elements accessible "gui" thread or main thread of program. thread has qapplication::exec(); ran on. has event loop propagates messages around.

look @ application output runtime errors qt tell about.

when crossing thread boundaries, sure utilize signals , slots.

and if accessing fellow member of thread class outside thread, sure utilize thread synchronization, practices, such prefacing access these members qmutexlocker locker(m_mutex);.

http://qt-project.org/doc/qt-5/threads.html

and implied title "gui thread", thread allowed things such drawing qpixmaps , accessing parts of qwidgets.

hope helps.

c++ multithreading qt crash x11

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -