Problem with QImage and QPixmap

  • Hey! I am developing application which is using OpenCV for capturing and processing images from camera and Qt for displaying them.
    I don't know exactly why but application suddenly started to crash without any traceback. I was developing it on WinXp with python27. It worked fine on Windows 7 and python26 but after installing python27 on that computer it started to crash with both pythons.
    I was able to trace and extract code which causes the crash:
    @from PySide.QtGui import QApplication,QImage, QPixmap
    app = QApplication("test")
    q_image = QImage("\255\0\0\0"(wh),
    This is not working at all (crashes on When I change (w,h) to (200,200) it is working ok, but resulting images are not something that I would expect - image data is corrupted. This application crashes both with PySide and PyQt4.
    I am very new to Qt so there might be something that I am not doing, or doing it wrong. But it seems to me like a serious bug.
    Please help me, because I don't know how to handle that problem.

  • Try changing line 4 to this:
    data = "\255\0\0\0"(wh)
    q_image = QImage(data,

  • Thanks, it worked! I was using img.tostring() (from OpenCV), that is why I didn't think that it is going to be garbage collected and I didn't suspect that Qt is so smart to use the same memory instead of allocating and copying. Thanks again!

Log in to reply

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