title: OpenCV's highgui in C++ Qt application
body: <p>I am trying to combine OpenCV's webcam access and image display functions with Qt's Network capabilities (Qt 4.8.1 C++ console application using OpenCV 2.4.2 <a href="http://docs.opencv.org/modules/highgui/doc/user_interface.html" rel="nofollow noreferrer">highgui</a>).
  I am currently trying to avoid converting a cv::Mat to a Qt format and displaying it by custom Qt GUI for simplicity.</p>
  
  <p>For this, I am creating a wrapper class that does all the OpenCV stuff (cap = new VideoCapture(), namedWindow(), cap->read(), imshow(), destroyAllWindows(), cap->release()) controlled by a QTimer an move it to a QThread.
  This mostly works (still <a href="https://stackoverflow.com/questions/19499117/qstring-and-opencv-cv-namedwindow">garbage characters in the window title</a>) but sometimes OpenCV creates a new window when the thread's parent class is receiving signals from its QTCPServer.
  This results in "dead" image windows that are not updated anymore.</p>
  
  <p>The order of creation (OpenCV thread / QTcpServer) does not seem to matter - however, if no client connects, I can see that OpenCV creates a small window first, that consequently gets enlarged to fit the video image size.
  If a client connects, the smaller window most of the times remains (Window title garbage like "ét), the newer window receives the image data properly (Window title garbage like ",ét").</p>
  
  <p>Not moving the OpenCV wrapper object to a thread does work as well, but the same problem occurs (even worse, two dead windows are created, the second of which already received an image frame).</p>
  
  <p>What could I generally be doing wrong to cause such behavior?</p>
  
  <p>I suspect that the problem may be caused by the named window being created and accessed in two different methods of my QOBject wrapper class (Constructor and slot).
  Or the QTCPServer is blocking the Qt event loop? Or that the OpenCV window handle is "garbage-collected" for some reason, when the Signal-Slot mechanism is triggered by QTCPServer events, and then <a href="http://docs.opencv.org/modules/highgui/doc/user_interface.html#imshow" rel="nofollow noreferrer">imshow</a> creates a new window?
  There is no obvious way of accessing the window by pointer, so this must be the reason. Removing the initial namedWindow() does away with the small, empty window but still, two windows are created.</p>
  
  <p>It seems I have to convert and display the images myself after all - or is there another way?</p>