Catching Qt X11 3dMouse events in child thread



  • I want to use 3dConnexion mouse in a 3D software.

    I am working on X11 Linux implementation, where mouse should be just a module checking for signals in its own child thread for events coming to main application window. Then it should signal a slot to manipulate application.

    However, I ran into problems with threading. I am trying to catch events through re-implementation of x11Event virtual class. When I run loop to catch events in child thread, I receive system error SIGSEGV. I figured out this is most likely answer to my problem:
    passing x11 events in qt

    Yet I have no idea how to fix this. I tried not using child thread but the loop for checking events really renders application window unusable. Thanks for any hints.

    Maybe it will be helpful to show the loop itself.

            Display *display;
            Window xwindow = window->winId();
            std::vector<float> signal_data;
            XEvent report;
            MagellanFloatEvent MagellanEvent;
    
    		bool MagellanLoop = true;
    		display = QX11Info::display();
    
    		/************************* Create 3D Event Types ***************************/
    		if ( !MagellanInit( display, xwindow ) ) {
    			qDebug() << "No driver is running. Exit ... " << endl;
    			exit(EXIT_FAILURE);
    		}
    		else {
    			qDebug() << "Mouse3dDevice::Mouse3DLinux: MagellanInit() = Success!" << endl;
    		}
    		/************************* Main Loop ***************************************/
    
    		while( MagellanLoop ) {
    			if( ! window->x11Event( &report ) ) {
    				qDebug() << "EventType = " << report.type << endl;
    				if ( report.type == ClientMessage ) {
    					if ( MagellanTranslateEvent( display, &report, &MagellanEvent, 1.0, 1.0 ) == MagellanInputMotionEvent) {
    						MagellanRemoveMotionEvents( display );
    
    						signal_data.clear();
    						signal_data.push_back(MagellanEvent.MagellanData[ MagellanX ]);
    						signal_data.push_back(MagellanEvent.MagellanData[ MagellanY ]);
    						signal_data.push_back(MagellanEvent.MagellanData[ MagellanZ ]);
    						signal_data.push_back(MagellanEvent.MagellanData[ MagellanA ]);
    						signal_data.push_back(MagellanEvent.MagellanData[ MagellanB ]);
    						signal_data.push_back(MagellanEvent.MagellanData[ MagellanC ]);
    
    						qDebug() <<  "x=" << signal_data[0] <<
    									"y=" << signal_data[1] <<
    									"z=" << signal_data[2] <<
    									"a=" << signal_data[3] <<
    									"b=" << signal_data[4] <<
    									"c=" << signal_data[5] << endl;
    
    						emit Mouse3dDevice::Move3d(signal_data);
    					}
    					else {
    						qDebug() << "Unrecognized - Not MagellanInputMotionEvent" << endl;
    					}
    				}
    			}
    		}
    

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    What backtrace do you get from the crash ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.