用setpixmap在Qlabel中画图,画359*359还能正常
显示,360*360就崩溃了。
新手刚开始学,望各位大侠不吝赐教,谢谢。下面是代码:
- #include "widget.h"
- #include "ui_widget.h"
- #include <QTimer>
- #include <QDebug>
- const int ovSize = 359;
- unsigned int ovArea = ovSize * ovSize;
- unsigned int *pImage = (unsigned int*)malloc(ovArea*sizeof(unsigned int));
- Widget::Widget(QWidget *parent) :
- QWidget(parent),
- ui(new Ui::Widget)
- {
- ui->setupUi(this);
- timer = new QTimer(this);
- connect(timer, SIGNAL(timeout()) , this, SLOT(updateNomal()));
- }
- Widget::~Widget()
- {
- delete ui;
- }
- void Widget::on_pushButton_clicked()
- {
- timer->start(500);
- }
- void Widget::updateNomal()
- {
- for (unsigned int i = 0; i < ovArea; ++i)
- {
- unsigned char *pb=(unsigned char *)(pImage+i);
- pImage[i] = 0;
- pb[0] = 85;
- pb[1] = 85;
- pb[2] = 85;
- }
- QByteArray imageByteArray = QByteArray( (const char*)pImage, ovArea*4 );
- uchar* transData = (unsigned char*)imageByteArray.data();
- QImage image = QImage(transData, ovSize, ovSize, QImage::Format_RGB32);
- ui->label->setPixmap(QPixmap::fromImage(image));
- }