why QPixmap along with QScale is causing segmentation fault on qt 5.9 ?
-
i have executed below code and it’s giving segmentation fault
#include <QApplication> #include <QLabel> #include <QPicture> #include <QPainter> #include <QPixmap> int main(int argc, char *argv[]) { QApplication a(argc, argv); const QSize qsize (100,100); QPixmap *bg = new QPixmap(200,200); QPainter* p = new QPainter(bg); *bg = bg->scaled(qsize) bg->fill(QColor(180, 192, 201)); p->setPen(QPen(QColor(180, 192, 201),1, Qt::SolidLine)); p->drawRect(0, 0, 200, 200); return a.exec(); } (added tags : mrjj)
if we comment *bg = bg->scaled(qsize) ; line no segmentation fault is found .
issue is found on Qt 5.9 version -
i have executed below code and it’s giving segmentation fault
#include <QApplication> #include <QLabel> #include <QPicture> #include <QPainter> #include <QPixmap> int main(int argc, char *argv[]) { QApplication a(argc, argv); const QSize qsize (100,100); QPixmap *bg = new QPixmap(200,200); QPainter* p = new QPainter(bg); *bg = bg->scaled(qsize) bg->fill(QColor(180, 192, 201)); p->setPen(QPen(QColor(180, 192, 201),1, Qt::SolidLine)); p->drawRect(0, 0, 200, 200); return a.exec(); } (added tags : mrjj)
if we comment *bg = bg->scaled(qsize) ; line no segmentation fault is found .
issue is found on Qt 5.9 version@nikhil_belani said in why QPixmap along with QScale is causing segmentation fault on qt 5.9 ?:
QPixmap *bg = new QPixmap(200,200); QPainter* p = new QPainter(bg);
Don't use
new
here. Just allocate QPainter and QPixmap on the stack.QPixmap bg1(200, 200); QPixmap bg2 = bg1.scaled(qsize);
-
@nikhil_belani said in why QPixmap along with QScale is causing segmentation fault on qt 5.9 ?:
QPixmap *bg = new QPixmap(200,200); QPainter* p = new QPainter(bg);
Don't use
new
here. Just allocate QPainter and QPixmap on the stack.QPixmap bg1(200, 200); QPixmap bg2 = bg1.scaled(qsize);
thanks same was code was working in 4.7 Qt version .
why its not working with qt 5.9 ?? -
thanks same was code was working in 4.7 Qt version .
why its not working with qt 5.9 ??@nikhil_belani said in why QPixmap along with QScale is causing segmentation fault on qt 5.9 ?:
thanks
You're welcome. Does your updated code work now?
same was code was working in 4.7 Qt version .
why its not working with qt 5.9 ??I don't know the exact cause, but lots of internal implementations changed between Qt 4.8 and Qt 5.0.
Even in Qt 4, the recommended way to use QPixmap was by-value, not by-pointer.
-
Hi
It crashes in the painter that have a reference to the BG and i assume
its due to implicit sharing being fooled with *b = implicit shared copy of scaled selfif you flip the order to
QPixmap *bg = new QPixmap(200,200);
bg=bg->scaled(qsize);
QPainter p = new QPainter(bg);
it wont crash.However as @JKSH points out. QPixmaps are meant to be used as non pointers.