• 3527阅读
  • 0回复

[提问]用setpixmap画360*360的图,程序崩溃了。 [复制链接]

上一主题 下一主题
离线q834081342
 

只看楼主 倒序阅读 楼主  发表于: 2016-03-25
用setpixmap在Qlabel中画图,画359*359还能正常显示,360*360就崩溃了。
新手刚开始学,望各位大侠不吝赐教,谢谢。下面是代码:
  1. #include "widget.h"
  2. #include "ui_widget.h"
  3. #include <QTimer>
  4. #include <QDebug>
  5. const int ovSize = 359;
  6. unsigned int ovArea = ovSize * ovSize;
  7. unsigned int *pImage = (unsigned int*)malloc(ovArea*sizeof(unsigned int));
  8. Widget::Widget(QWidget *parent) :
  9.     QWidget(parent),
  10.     ui(new Ui::Widget)
  11. {
  12.     ui->setupUi(this);
  13.     timer = new QTimer(this);
  14.     connect(timer, SIGNAL(timeout()) , this, SLOT(updateNomal()));
  15. }
  16. Widget::~Widget()
  17. {
  18.     delete ui;
  19. }
  20. void Widget::on_pushButton_clicked()
  21. {
  22.     timer->start(500);
  23. }
  24. void Widget::updateNomal()
  25. {
  26.     for (unsigned int i = 0; i < ovArea; ++i)
  27.     {
  28.         unsigned char *pb=(unsigned char *)(pImage+i);
  29.         pImage[i] = 0;
  30.         pb[0] = 85;
  31.         pb[1] = 85;
  32.         pb[2] = 85;
  33.     }
  34.     QByteArray imageByteArray = QByteArray( (const char*)pImage,  ovArea*4 );
  35.     uchar*  transData = (unsigned char*)imageByteArray.data();
  36.     QImage image = QImage(transData, ovSize, ovSize, QImage::Format_RGB32);
  37.     ui->label->setPixmap(QPixmap::fromImage(image));
  38. }

快速回复
限100 字节
 
上一个 下一个