Bug in QImage
-
When I build an run this snippet on MinGW it works, on MSCV it doesn't. Both with newest Qt6.5.2 updates. It's a known bug? I can't find anything on Internet?
extern BaseModel basemodel; [...] void BoardView::paintPieces(QPainter *p) { auto w = p->window().width(); //p->viewport().width(); auto h = p->window().height(); //p->viewport().height(); p->drawPixmap( QRect(50, 50, w, h), QPixmap::fromImage(basemodel.board.pieces[0][0].img)); } ________________________ [console output on MinGW] QImage(QSize(102, 102),format=QImage::Format_ARGB32,depth=32,devicePixelRatio=1,bytesPerLine=408,sizeInBytes=41616) [console output on MSCV 2019] QImage(null)
Best regards
-
@wostka said in Bug in QImage:
In the ctor of board from a struct named Piece
Why don't you show the code?
One workaround: Have to add
Q_INIT_RESOURCE(res); //res = the .qrc file, e.g. res.qrc
then it run under MSVC. Not a bug, a feature... :D
see https://doc.qt.io/qt-6/resources.html#explicit-loading-and-unloading-of-embedded-resources
Thanks to @jsulm and @Chris-Kawa
-
When I build an run this snippet on MinGW it works, on MSCV it doesn't. Both with newest Qt6.5.2 updates. It's a known bug? I can't find anything on Internet?
extern BaseModel basemodel; [...] void BoardView::paintPieces(QPainter *p) { auto w = p->window().width(); //p->viewport().width(); auto h = p->window().height(); //p->viewport().height(); p->drawPixmap( QRect(50, 50, w, h), QPixmap::fromImage(basemodel.board.pieces[0][0].img)); } ________________________ [console output on MinGW] QImage(QSize(102, 102),format=QImage::Format_ARGB32,depth=32,devicePixelRatio=1,bytesPerLine=408,sizeInBytes=41616) [console output on MSCV 2019] QImage(null)
Best regards
-
@wostka Where do you output anything on console?
To me it is not clear what exactly does not work.@jsulm I have adapt the code.
The original code is a loop which iterates a 2-dim Array (pieces) which has stored e.g. an QImage (img)...This Array is stored in a class called board and this is stored in a class called basemodel. basemodel ist global.
The methode paintPieces is called in the paintEvent methode of a view which paints the board of a game. The methode paintPieces paints the pieces of the board.
The console output comes fromp->drawPixmap(... qDebug() << basemodel.board.pieces[0][0].img;
The problem is, that the same code generated by different compilers one times works, and at the other time not and I dont know why.
Hope its clearer now whats the situation. -
@jsulm I have adapt the code.
The original code is a loop which iterates a 2-dim Array (pieces) which has stored e.g. an QImage (img)...This Array is stored in a class called board and this is stored in a class called basemodel. basemodel ist global.
The methode paintPieces is called in the paintEvent methode of a view which paints the board of a game. The methode paintPieces paints the pieces of the board.
The console output comes fromp->drawPixmap(... qDebug() << basemodel.board.pieces[0][0].img;
The problem is, that the same code generated by different compilers one times works, and at the other time not and I dont know why.
Hope its clearer now whats the situation. -
If those are images read from files or resources you're most likely just missing the plugin for that format in your deployment directory.
-
If those are images read from files or resources you're most likely just missing the plugin for that format in your deployment directory.
@jsulm In the ctor of board from a struct named Piece
@Chris-Kawa The plugins seems to be on the right place. The problem arise too, if I "deploy" the exe with windeployqt. TheqDebug() << QImageReader::supportedImageFormats();
gives in both cases ".png", whats right.
Perhaps some pics:
This with MinGW-Kit
This with MSVC
If I change the Kit from MinGW to MSVC.
-
@jsulm In the ctor of board from a struct named Piece
@Chris-Kawa The plugins seems to be on the right place. The problem arise too, if I "deploy" the exe with windeployqt. TheqDebug() << QImageReader::supportedImageFormats();
gives in both cases ".png", whats right.
Perhaps some pics:
This with MinGW-Kit
This with MSVC
If I change the Kit from MinGW to MSVC.
@wostka Before you jump to conclusions do a basic test:
int main(int argc, char *argv[]) { QApplication a(argc, argv); qDebug() << QImage("C:/Explicit/path/to/some/file.png"); }
Does that work?
-
@jsulm In the ctor of board from a struct named Piece
@Chris-Kawa The plugins seems to be on the right place. The problem arise too, if I "deploy" the exe with windeployqt. TheqDebug() << QImageReader::supportedImageFormats();
gives in both cases ".png", whats right.
Perhaps some pics:
This with MinGW-Kit
This with MSVC
If I change the Kit from MinGW to MSVC.
@wostka said in Bug in QImage:
In the ctor of board from a struct named Piece
Why don't you show the code?
-
@wostka said in Bug in QImage:
In the ctor of board from a struct named Piece
Why don't you show the code?
One workaround: Have to add
Q_INIT_RESOURCE(res); //res = the .qrc file, e.g. res.qrc
then it run under MSVC. Not a bug, a feature... :D
see https://doc.qt.io/qt-6/resources.html#explicit-loading-and-unloading-of-embedded-resources
Thanks to @jsulm and @Chris-Kawa
-
-
One workaround: Have to add
Q_INIT_RESOURCE(res); //res = the .qrc file, e.g. res.qrc
then it run under MSVC. Not a bug, a feature... :D
see https://doc.qt.io/qt-6/resources.html#explicit-loading-and-unloading-of-embedded-resources
Thanks to @jsulm and @Chris-Kawa
@wostka said in Bug in QImage:
Not a bug, a feature... :D
No feature but a mandatory thing - otherwise there is no reference to the resource and the lnker can throw it away.