title: Qt 5 with USB video grabber
body: <p>My demo code is to choose a camera from the integrated camera of my laptop, and a USB video grabber (STK1160). My code is attached.</p>
  
  <p>main.cpp:</p>
  
  <pre><code>#include "mainwindow.h"
  #include &lt;QApplication&gt;
  
  int main(int argc, char *argv[])
  {
      QApplication a(argc, argv);
      MainWindow w;
      w.show();
  
      return a.exec();
  }
  </code></pre>
  
  <p>mainwindow.h:</p>
  
  <pre><code>#ifndef MAINWINDOW_H
  #define MAINWINDOW_H
  
  #include &lt;QMainWindow&gt;
  #include &lt;QCamera&gt;
  #include &lt;QCameraInfo&gt;
  #include &lt;QCameraImageCapture&gt;
  
  namespace Ui {
      class MainWindow;
  }
  
  class MainWindow : public QMainWindow {
  
      Q_OBJECT
  
  public:
      explicit MainWindow(QWidget *parent = 0);
      ~MainWindow();
  
  private:
      Ui::MainWindow *ui;
      QList &lt;QCameraInfo&gt; camList;
      QCamera *camera;
  
  private slots:
      void onCameraChanged(int);
  };
  
  #endif // MAINWINDOW_H
  </code></pre>
  
  <p>mainwindow.cpp</p>
  
  <pre><code>#include "mainwindow.h"
  #include "ui_mainwindow.h"
  
  MainWindow::MainWindow(QWidget *parent) :
      QMainWindow(parent), ui(new Ui::MainWindow) {
      ui-&gt;setupUi(this);
  
      camera = NULL;
      connect(ui-&gt;cameraComboBox,static_cast&lt;void (QComboBox::*)(int)&gt;(&amp;QComboBox::currentIndexChanged),this,
              &amp;MainWindow::onCameraChanged);
  
      // find all available cameras and put them in the combo box
      camList = QCameraInfo::availableCameras();
      for(QList &lt;QCameraInfo&gt;::iterator it = camList.begin();it!=camList.end();++it) {
          ui-&gt;cameraComboBox-&gt;addItem(it-&gt;description());
      }
  }
  
  MainWindow::~MainWindow() {
      delete ui;
  }
  
  void MainWindow::onCameraChanged(int idx) {
      if(camera != NULL) {
          camera-&gt;stop();
      }
      camera = new QCamera(camList.at(idx),this);
      camera-&gt;setViewfinder(ui-&gt;viewfinder);
      camera-&gt;setCaptureMode(QCamera::CaptureStillImage);
      camera-&gt;start();
  }
  </code></pre>
  
  <p>My problem is that when I choose the USB grabber from the combo box, I got the following error message:</p>
  
  <pre><code>libv4l2: error turning on stream: Message too long
  CameraBin error: "Error starting streaming on device '/dev/video1'."
  CameraBin error: "Could not negotiate format"
  </code></pre>
  
  <p>and the camera view is all black. Anyone has any idea? I have tested my video input on an AV screen, it works well.</p>