+ -
当前位置:首页 → 问答吧 → 求助 内存出问题

求助 内存出问题

时间:2011-12-02

来源:互联网

C/C++ code

void Icon_memory::on_pushButton_released()
{
    
        QImage * image = new QImage(tr("Sunset.jpg"));
        QSize s = ui.pushButton->size();//the button you would to set the back;
        QImage * i2 =new QImage(image->scaled(s));//adapt the size of button;
        QIcon iocn_ = QIcon(QPixmap::fromImage(*i2));
    1)    ui.pushButton->setIcon(iocn_);
        ui.pushButton->setIconSize(s);
        
        delete i2;
        delete image;
        
}

void Icon_memory::on_pushButton_pressed()
{
    


    QImage * image = new QImage(tr("Winter.jpg"));
    QSize s = ui.pushButton->size();//the button you would to set the back;
    QImage * i2 =new QImage(image->scaled(s));//adapt the size of button;
    QIcon iocn_ = QIcon(QPixmap::fromImage(*i2));
1)    ui.pushButton->setIcon(iocn_);
    ui.pushButton->setIconSize(s);
    
    delete i2;
    delete image;
    
}


上面是QT程序 就是设置button 按下弹起的背景不一样,但有问题,每次响应动作内存就要增加,如果将 1)删除掉 内存不会有任何变化。我被整了1个月了但是在找不出原因。我在QT 和 c++那边发帖 根本没人理。希望MFC的大牛们给我的思路啊。
我快崩溃了。

作者: tt2com   发布时间: 2011-12-02

不懂这个编程。。。

看不来任何编程问题。。。顶顶!
ui.pushButton->setIcon(iocn_);
是添加icon,内存当然会增加了。。

难道增加很多。。

作者: shen_wei   发布时间: 2011-12-02

分析下
setIcon地实现,问题是否在这里?

作者: gameslq   发布时间: 2011-12-02

setIcon函数里是不是分配内存没释放?

作者: xiaoguailong3   发布时间: 2011-12-02

热门下载

更多