Qt没有使用openni2显示QImage

时间:2014-08-04 18:37:44

标签: qt openni qimage qlabel

我试图在QImage中显示QLabel,但它似乎无法正常工作。我有这样的事情:

 ui->color->setPixmap(QPixmap::fromImage(colorimg));
 ui->color->show();

图像设置为:

colorimg = getColorImage();

其中:

getColorImage(){
    const unsigned char *color_pixel;
    VideoStream *stream = &color;

    int ready_index;
    OpenNI::waitForAnyStream(&stream, 1, &ready_index);

    if(ready_index == 0)
    {
        VideoFrameRef color_frame;
        color.readFrame(&color_frame);

        if(color_frame.isValid())
        {
            color_pixel = (const unsigned char*)color_frame.getData();
        }
    }
    QImage image = QImage(color_pixel, color.getVideoMode().getResolutionX(), color.getVideoMode().getResolutionY(), QImage::Format_RGB888);
    return image;
}

我的应用程序运行并且不会生成错误,但名为color的标签仅显示默认的"文本标签"。有人能帮我吗?

1 个答案:

答案 0 :(得分:0)

我已经解决了,问题不在于使用Openni,而是由Qt推动。 Qt只能在控件返回事件循环时更新UI。因此,您必须调用qApp->processEvents();才能强制更新UI。