hi,guys:
i receive some picture data from internet,and now want to display in a widget with my form.(ON RED HAT ENTERPRISE Linux 5.0)
the "widget" is inherited from QWidget, and use these code to attatch to the mainform:
ui->widget->setVisible(0); //a Widget to provide geometry
//define as : class WidgetVideoArea : public QWidget
videoarea = new WidgetVideoArea(this);
videoarea->setGeometry(ui->widget->geometry());
videoarea->show();
then ,i recevie data from thread1,and emit a signal to mainwindow,so the picture can update.
void MainWindow
::updateVideo(QByteArray videobufs
) {
const char *data = videobufs.constData();
videoarea->setRepaintFlag(smage);
videoarea->repaint();
}
void MainWindow::updateVideo(QByteArray videobufs)
{
const char *data = videobufs.constData();
QImage smage((uchar*)data,240,320,QImage::Format_RGB16);
videoarea->setRepaintFlag(smage);
videoarea->repaint();
}
To copy to clipboard, switch view to plain text mode
now it works.
But i think that will freeze GUI. so i create another thread,thread2, to update the picture separately.
the function updateVideo(QByteArray videobufs) above is set to "public",so i can use it in thread2.
However,when i do that, application output:
X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Major opcode: 62 (X_CopyArea)
Resource id: 0x0
QPixmap: It is not safe to use pixmaps outside the GUI thread
...............
so how can i update the widget in a thread? will these appear in embedded board?(i will port to ARM later).
i used this method in VisualC++ before, and had no problem.
thanks.
Bookmarks