我有一個軟件通過網絡將JPG發送到應該顯示這些圖像的GUI客戶端。我基本上想要顯示他們到一個QT窗口,但我有問題如何QT顯示連續的JPG。我做了一個測試,看看我是否通過將它打印到文件中來正確地獲取圖像,並檢查出正常。這裏的主要代碼:使用QT查看來自相機的流式圖像
int main(int argc, char *argv[]) {
// initialize resources, if needed
// Q_INIT_RESOURCE(resfile);
QApplication app(argc, argv);
CameraWindow cw;
cw.show();
//app.setActiveWindow(&cw);
cw.getData(); // this paints the window
return app.exec();
}
下面是初始化插件的代碼:
class CameraWindow : public QDialog {
Q_OBJECT
public:
bool serverConnected;
void getData();
CameraWindow()
{
imgl = new QLabel;
widget.scrollImage->setWidget(imgl);
widget.scrollImage->setBackgroundRole(QPalette::Dark);
}
QLabel *imgl;
virtual ~CameraWindow();
private:
Ui::CameraWindow widget;
};
這是應該繪製圖像這是內部的無限屏幕上的代碼的相關部分循環:
的getData()從主叫:
while (myrval < Header.imageSize) {
myrval = myrval + recv(msgsock, (char*) ((int) buff + myrval),
Header.imageSize- myrval, 0);
}
//buff contains the jpg at this point
QPixmap imgjpg;
imgjpg.loadFromData((const unsigned char*)buff, Header.imageSize, "JPG");
//scroll image is the parent that displays child
//in this case, the label
imgl->setPixmap(imgjpg);
我得到這個爲工作只是一個從文件加載的圖像,但是當我對一組流式圖像使用相同的方法時,這不起作用。我是Qt新手,所以我確信我有一個微妙的錯誤。
非常感謝!
你是如何繞過你的'recv()'調用並加載圖像的? (你可以將這兩項任務分解爲各自的功能嗎?) – sarnold