Hello,

I'm trying to create a QT program to display the mjpg frames of my ip camera. For this i used QHttp without succes. On the internet i found out that it was also possible with QNetworkAccessManager. Now i've managed to show single images by using QNetworkReply and put it in a QPixmap. I'm sure it als must be possible for mjpg images but i can't figure out how.

Can anyone give me some advise. I can't use Opencv because finaly the application has to be written in QT embedded. If i'm right, i have to use the virtual framebuffer to show the mjpg images of the camera.

Below you can see my code.

Qt Code:
  1. MainWindow::MainWindow(QWidget *parent) :
  2. QMainWindow(parent),
  3. ui(new Ui::MainWindow)
  4. {
  5. ui->setupUi(this);
  6. m_netwManager = new QNetworkAccessManager(this);
  7. connect(m_netwManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(slot_netwManagerFinished(QNetworkReply*)));
  8. connect(m_netwManager,SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),this,SLOT(slot_netwManagerFinished(QNetworkReply*,QAuthenticator*)));
  9. }
  10.  
  11. void MainWindow::on_action_Download_triggered()
  12. {
  13. QUrl url(ui->txtImageAddress->text());
  14. QNetworkRequest request(url);
  15. m_netwManager->get(request);
  16. }
  17.  
  18. void MainWindow::slot_netwManagerFinished(QNetworkReply*,QAuthenticator* auth)
  19. {
  20. auth->setUser("admin");
  21. auth->setPassword("admin");
  22. }
  23.  
  24. void MainWindow::slot_netwManagerFinished(QNetworkReply *reply)
  25. {
  26.  
  27. if (reply->error() != QNetworkReply::NoError) {
  28. reply->deleteLater();
  29. return;
  30. }
  31.  
  32. QString contentType = reply->header( QNetworkRequest::ContentTypeHeader ).toString();
  33.  
  34. if (contentType == "image/jpeg")
  35. {
  36.  
  37. QVariant redir = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
  38. if (redir.isValid()) {
  39. QUrl url = redir.toUrl();
  40. if (url.isRelative()) {
  41. url.setScheme(reply->url().scheme());
  42. url.setEncodedHost(reply->url().encodedHost());
  43. }
  44. QNetworkRequest req(url);
  45. m_netwManager->get(req);
  46. reply->deleteLater();
  47. return;
  48. }
  49.  
  50. QByteArray jpegData = reply->readAll();
  51.  
  52. QPixmap pixmap;
  53. pixmap.loadFromData(jpegData);
  54. ui->lblImage->setPixmap(pixmap);
  55.  
  56. reply->deleteLater();
  57.  
  58. }
  59. else
  60. {
  61. //VIDEO MJPG DATA
  62.  
  63.  
  64. }
  65. }
To copy to clipboard, switch view to plain text mode