Results 1 to 3 of 3

Thread: saving QPixmap to QIODevice gives SEGV error

  1. #1
    Join Date
    Sep 2010
    Location
    Bangalore
    Posts
    169
    Thanks
    59
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default saving QPixmap to QIODevice gives SEGV error

    Hello all,

    I am trying to capture a screenshot of my Application in a QPixmap and then save it to a QIODevice. But it's giving segmentation fault.
    Not able to figure out why.

    Here's the code-

    Qt Code:
    1. QPixmap pix = QPixmap::grabWindow(QApplication::desktop()->winId());
    2.  
    3. ui.myLabel->setPixmap(pix); //This is fine. Displays the Screenshot
    4. ui.myLabel->setScaledContents(true);
    5.  
    6. QByteArray bArray;
    7. QBuffer buffer(&bArray);
    8. buffer.open(QIODevice::WriteOnly);
    9.  
    10. qDebug()<<"before";
    11. pix.save(&buffer); //Gives SEGV Error
    12. qDebug()<<"after";
    13.  
    14. buffer.close();
    To copy to clipboard, switch view to plain text mode 


    Not able to figure out what the problem is.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,141
    Thanks
    235
    Thanked 661 Times in 651 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: saving QPixmap to QIODevice gives SEGV error

    You haven't given a format in the save() call. Try using something like "PNG" as the second parameter.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. The following user says thank you to d_stranz for this useful post:

    sattu (12th July 2017)

  4. #3
    Join Date
    Sep 2010
    Location
    Bangalore
    Posts
    169
    Thanks
    59
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: saving QPixmap to QIODevice gives SEGV error

    Quote Originally Posted by d_stranz View Post
    Try using something like "PNG" as the second parameter.
    Thanks a lot. That solved the issue but now I am facing another issue.
    After saving the image file in PNG format, I am trying to read the same file in another application and again save it in another name. (Extremely sorry if it sounds strange but please bear with me ) It's crashing.


    The first app-
    Qt Code:
    1. QPixmap pix = QPixmap::grabWindow(QApplication::desktop()->winId());
    2.  
    3. QImage img = pix.toImage(); //Converting to QImage so that I can know which format it is in.
    4.  
    5. qDebug()<<"size: "<<img.size();
    6. qDebug()<<"format: "<<img.format(); //returns QImage::Format_RGB16
    7.  
    8. img.save("/pefis/bin/test.png", "PNG"); //This works fine
    To copy to clipboard, switch view to plain text mode 


    In another app-
    Qt Code:
    1. QImage img("/pefis/bin/test.png", "PNG");
    2.  
    3. qDebug()<<"size: "<<img.size();
    4. qDebug()<<"format: "<<img.format(); //returns QImage::Format_RGB32
    5.  
    6. img.save("/pefis/bin/test1.png", "PNG"); //Crashes here. Gives SEGV Error
    To copy to clipboard, switch view to plain text mode 


    First the Image format is automatically changing and then it is crashing when I am trying to save it in another name.
    Please point out what mistake I am committing.


    -Thanking You,
    sattu

Similar Threads

  1. qmldump error - segv
    By kornicameister in forum Qt Quick
    Replies: 1
    Last Post: 6th October 2011, 10:51
  2. Saving QPixmap resutls in corrupt JPG
    By Pit in forum Qt Programming
    Replies: 18
    Last Post: 21st July 2010, 08:59
  3. segv error in signal
    By Sheng in forum Qt Programming
    Replies: 7
    Last Post: 8th April 2009, 18:14
  4. Saving the widget class as a QPixmap
    By zgulser in forum Newbie
    Replies: 11
    Last Post: 2nd February 2009, 09:48
  5. Saving a QPixmap Object problem
    By StrikerX in forum General Programming
    Replies: 4
    Last Post: 15th November 2007, 02:19

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.