Results 1 to 7 of 7

Thread: Why does this QPixmap::fromImage() crash?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2008
    Posts
    53
    Thanks
    10

    Default Why does this QPixmap::fromImage() crash?

    Hello, I have the following lines of code:

    Qt Code:
    1. QImage tImage(50,50,QImage::Format_Indexed8);
    2. tImage.fill(0);
    3. QPixmap tempImagePix = QPixmap::fromImage(tImage);
    To copy to clipboard, switch view to plain text mode 

    When I run this it crashes saying:

    Debug error!
    Module: 4.5.0
    File: global\qglobal.cpp
    Line:1994

    ASSERT failure in QVector<T>::at: "index out of range", file
    ...\include\qtcore\../../src/corelib/tools/qvector.h, line 327

    What is causing the problem? Thank you.

  2. #2
    Join Date
    Jul 2009
    Location
    ChongQing, China
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Why does this QPixmap::fromImage() crash?

    I run this very well. maybe something else is wrong.

  3. #3
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why does this QPixmap::fromImage() crash?

    Investigate your stack trace when you get this assert failure. That will tell you which part of your code causes this problem.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  4. #4
    Join Date
    Apr 2008
    Posts
    53
    Thanks
    10

    Default Re: Why does this QPixmap::fromImage() crash?

    Well the error is from the last line, fromImage.

    When i look at the call stack the error is coming from:
    fromImage()-> convertToFormat()-> convert_Indexed8_to_X32()-> QVector <unsigned int>::at(0)

    inline const T &QVector<T>::at(int i) const
    { Q_ASSERT_X(i >= 0 && i < d->size, "QVector<T>::at", "index out of range");
    return d->array[i]; }
    template <typename T>

    I also tried to change the size of my QImage, but same thing. Please help, thank you.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Why does this QPixmap::fromImage() crash?

    Aren't you by any chance calling that from an external thread?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Apr 2008
    Posts
    53
    Thanks
    10

    Default Re: Why does this QPixmap::fromImage() crash?

    The problem was that I didn't have a colormap, which was the array that it was trying to index.

    Apparently when I try to use fromImage: "..the image is first converted to a 32-bit pixmap and then filled with the colors in the color table." (Qt documentation)

    Which is kind of weird that I need to initialize a color table even though i'm using QImage::Format_Indexed8

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Why does this QPixmap::fromImage() crash?

    What do you mean by "even though"? If you are using an indexed format then do you need a colour table. It won't get initialized on its own...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Crash: Heap corruption due to selectedRows()
    By Ankitha Varsha in forum Qt Programming
    Replies: 16
    Last Post: 1st October 2010, 00:55
  2. Replies: 28
    Last Post: 9th March 2010, 08:59
  3. QString comparison gives wierd crash
    By supergillis in forum Qt Programming
    Replies: 0
    Last Post: 1st June 2009, 22:09
  4. Replies: 2
    Last Post: 13th August 2008, 17:46
  5. QTimer ->start(0) + OpenGL + resize/move window => crash
    By anthibug in forum Qt Programming
    Replies: 5
    Last Post: 8th July 2008, 11:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.