saman_artorious
28th October 2013, 10:30
I receive a byte array which contains PNG file from network. I need to set this to a pixmap and set it as a texture to my QGlWidget. As I run the program below, pixmap is in debug mode and does not contain anything. However, bytes contains the whole byte array received from network.
void MainWindow::dataFromServer(QByteArray bytes)
{
// QByteArray bytes;
QBuffer buffer(&bytes);
QPixmap pixmap;
// pixmap = QPixmap::grabWidget(this);
buffer.open(QIODevice::WriteOnly);
pixmap.save(&buffer, "PNG"); // writes pixmap into bytes in PNG format
emit sendPixmapToWidget(pixmap);
}
and here I set the pixmap to texture:
void GlWidget::pixmapCatchFromForm(QPixmap pixmap) {
deleteTexture(texture);
// image->loadFromData(bytes, "PNG");
texture = bindTexture(pixmap);
qDebug() << texture; // returns 1
updateGL();
}
void MainWindow::dataFromServer(QByteArray bytes)
{
// QByteArray bytes;
QBuffer buffer(&bytes);
QPixmap pixmap;
// pixmap = QPixmap::grabWidget(this);
buffer.open(QIODevice::WriteOnly);
pixmap.save(&buffer, "PNG"); // writes pixmap into bytes in PNG format
emit sendPixmapToWidget(pixmap);
}
and here I set the pixmap to texture:
void GlWidget::pixmapCatchFromForm(QPixmap pixmap) {
deleteTexture(texture);
// image->loadFromData(bytes, "PNG");
texture = bindTexture(pixmap);
qDebug() << texture; // returns 1
updateGL();
}