Вопрос

I have an qt symbian project and I set background image programmatically on constracter of QMainWindow. but I discover that bug, If I open and close that QMainWindow for example 15 times, pixmap I used for background returns null. I made that pixmap static at my static class which I keep some information during execution, but it does not help my situation. I will be thankfull for any help. Here is some code example

SettingsWindow::SettingsWindow(QWidget *parent) :
QMainWindow(parent), ui(new Ui::Settings)
{
ui->setupUi(this);
// getting screen geometry
QDesktopWidget* desktopWidget = qApp->desktop();
QRect screenGeometry = desktopWidget->screenGeometry();

ConstantVariables* pointer = ConstantVariables::CVinstance();

set image with screen geometry
QPalette* palette = new QPalette();
palette->setBrush(QPalette::Background,*(new QBrush(pointer->backGround->scaled(screenGeometry.width(),screenGeometry.height()))));
setPalette(*palette);     
Это было полезно?

Решение

You would have to step through the source to verify this, but one situation that causes the QPixmap constructor to return null is if it cannot allocate enough memory for the pixmap. (We had this problem with very large images.)

Are you successfully deallocating the memory used for the previous pixmaps? Run a memory profiler as you execute your application and see if memory is leaking.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top