Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QPixmap sometimes does not load file, other times it does
qtdummy last edited by
This is a similar application as the windows photo viewer: I have a directory with 145 files.The user picks a file and the program displays it on the screen. Then the user presses a left/right button to display the previous/next file. Internally I keep all the pixmaps in memory (for speed reasons) and only load when a new file is selected. Some files return NULL (not loaded) when using "new QPixmap(filename);" But only if I start from file 1 and work up to it. If I start with the file it displays fine. It looks like a 'not enough memory' problem as from there it only shows/load small pictures, anything as long as the total memory<404M. I checked and I have used ~397M. I would assume I have ~1.6G still available (windows-7 x64 machine with 16G memory)
It's hard to say anything without looking at the code.
bq. I keep all the pixmaps in memory (for speed reasons) and only load when a new file is selected
I don't think I follow. So do you load all at once or not? Or do you load on demand and just never delete? In any case, this seems terrible wasteful. I mean 400MB for a picture viewer? What if there are 1000 files? You'll run out of address space pretty quick if it's a 32 bit app.
It's not a direct response to your problem, as, as I said, it's hard to guess what's happening, but I would consider changing your design to keep around say 5 or 7 of the images - the current one, two/three previous and pre-load ahead the next two/three. When you switch (left or right) you could delete from one side and load on the other. If you do it in a separate thread the performance and smoothness would be much better.