Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPixmap VS QImage, X server problem
Forum Updated to NodeBB v4.3 + New Features

QPixmap VS QImage, X server problem

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 8.3k Views 1 Watching
  • 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.
  • L Offline
    L Offline
    luca
    wrote on last edited by
    #1

    Hi all,
    I'm developing an application (for LINUX) that show some images downloaded from the web. The application works fine but I found a strange behavior of the X server.
    The part of code is:
    @
    void VisualizzazioneWidget::immagineArrivata(bool esito)
    {
    pixmap.loadFromData(http.readAll());
    if(pixmapItem==NULL)
    {
    pixmapItem=scene.addPixmap(pixmap);
    }
    else
    {
    pixmapItem->setPixmap(pixmap);
    }
    }
    @

    This function is execute every second.
    I'v seen that in a PC without a dedicated graphic card the X server process memory usage grow up endless. While in a PC with a dedicated graphic card it doesn't append.
    To solve the problem I repalced QPixmap with QImage and all works fine:
    @
    void VisualizzazioneWidget::immagineArrivata(bool esito)
    {
    image.loadFromData(http.readAll());
    if(pixmapItem==NULL)
    {
    pixmapItem=scene.addPixmap(QPixmap().fromImage(image));
    }
    else
    {
    pixmapItem->setPixmap(QPixmap().fromImage(image));
    }
    }
    @
    I also replaced all other occurrence of QPixmap with QImage in other part of the application.

    I seen this in QT documentation:
    @Note also that QPixmap, unlike QImage, may be hardware dependent. On X11, Mac and Symbian, a QPixmap is stored on the server side while a QImage is stored on the client side (on Windows, these two classes have an equivalent internal representation, i.e. both QImage and QPixmap are stored on the client side and don't use any GDI resources).
    @
    but why there is no problem if I have a dedicated graphics card? Is it a bug?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DenisKormalev
      wrote on last edited by
      #2

      Maybe not Qt problem? Looks like it is problem in intel (or what integrated card do you use) driver for xorg . As for me I noticed some other non obvious float bugs (but for now they are look like fixed) in it.

      1 Reply Last reply
      0
      • L Offline
        L Offline
        luca
        wrote on last edited by
        #3

        As documentation said:
        "QPixmap is stored on the server side"
        but I don't know if I must free X server memory in a different way.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jorj
          wrote on last edited by
          #4

          [quote author="Luca" date="1276064407"]but I don't know if I must free X server memory in a different way.[/quote]

          It would seem unlikely as things work fine with a dedicated graphics card, plus freeing X Server memory doesn't strike me as the Qt way of doing things!

          I'm with Denis, seems to be a driver issue with linux.

          1 Reply Last reply
          0
          • L Offline
            L Offline
            luca
            wrote on last edited by
            #5

            I found this link that talk about X server and memory leak:
            http://www.rahul.net/kenton/txa/feb96.html

            There is a part where it says:
            @
            Who Frees the Memory and How?

            Now that you've determined when dynamic memory is allocated by the X libraries, the next questions should be:

            1. does the application have to free the memory?
            2. if yes, when can it safely free the memory?
            3. what function should be used to free the memory?

            Unfortunately, the X and, especially, the Motif documentation is not always clear about which case applies to a particular programming interface. In this section, I'll discuss some general guidelines in these areas. Next month's column will cover specific programming interfaces in more specific detail.

            Freeing dynamic memory that shouldn't be freed can lead to many problems in the X libraries, including corrupting memory in use by X, freeing memory twice, and writing to invalid memory. Freeing memory with the wrong function can cause it to be improperly freed, including not freeing all the allocated memory.
            @

            1 Reply Last reply
            0
            • ? This user is from outside of this forum
              ? This user is from outside of this forum
              Guest
              wrote on last edited by
              #6

              does QPixmap::ShareMode have anything to do with this. It says on x11, you have to explicitly delete the pixmap handle. how would one use it?

              also, not related to leak, but I've found QImageReader to be more efficient in terms of memory footprint, you might cross check.. below from qt docs:

              @
              QImageReader is a specialized class which gives you more control when reading images. For example,
              you can read an image into a specific size by calling setScaledSize(), and you can select a clip rect,
              effectively loading only parts of an image, by calling setClipRect(). Depending on the underlying support
              in the image format, this can save memory and speed up loading of images
              @

              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