title: Xlib: unexpected async reply when testing Qt application from a separate QThread within same Qt application
body: <p>I am trying to create a test for my Qt appication. The aim is to test the GUI of the application by moving the mouse around and clicking on QGraphicsItems or QWidgets using the X11 library.</p>
  
  <p>The test is written as a plugin for my Qt application. It launches a separate QThread and in the run() function I do the mouse moving. Lets call this the 'test running thread'</p>
  
  <p>However I also need to get the structure of the GUI i.e. the location of various widgets, so in the 'test running thread' I go through the QApplication::topLevelWidgets() and find the one I am interested in. Then I call mapToGlobal() on this widget to gets its global position. This position can then be fed to the X11 mouse functions to move the mouse over the widget.</p>
  
  <p>This works generally but once in a while I get this error 'Xlib: unexpected async reply'
  Some googling revealed that this can be due to setting QWidget positions or trying to update them from another thread.</p>
  
  <p>But I simply get information about widgets in another thread. Why would that cause a problem ? :(</p>
  
  <p>If all else fails, I am prepared to setup some kind of communication queue back to the main(GUI) thread. The 'test running thread' will place requests for information about widgets on the queue and the GUI thread can respond to them.</p>
  
  <p>The reason why the plugin launches a separate thread to move the mouse is because the GUI must continue to respond to events otherwise the entire point of the exercise is lost. I know that I could also <em>not</em> use a thread, and simply <em>move the mouse in the main thread</em> calling processEvents() regularly. Thats the other option I have I guess.</p>
  
  <p>Any ideas from someone who has been down this route before would be very helpful.
  Thanks !</p>