Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. Problem with QImage and QPixmap

Problem with QImage and QPixmap

Scheduled Pinned Locked Moved Language Bindings
3 Posts 2 Posters 7.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maciej.pawlisz
    wrote on last edited by
    #1

    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")
    (w,h)=(400,400);
    q_image = QImage("\255\0\0\0"(wh),
    w,h,
    QImage.Format_RGB32)
    q_image.save('qimage.jpg','JPG')
    pixmap=QPixmap(w,h)
    pixmap.convertFromImage(q_image)
    pixmap.save('qpixmap.jpg','JPG')
    exit()
    @
    This is not working at all (crashes on q_image.save()). 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.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      baysmith
      wrote on last edited by
      #2

      Try changing line 4 to this:
      @
      data = "\255\0\0\0"(wh)
      q_image = QImage(data,
      w,h,
      QImage.Format_RGB32)
      @

      Nokia Certified Qt Specialist.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        maciej.pawlisz
        wrote on last edited by
        #3

        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!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved