The error of ‘VIDIOC_QUERYMENU: Invalid argument’

Screenshot-C-C++ - rgbwebcam-src-rgbwebcam.cpp - Eclipse SDK

Screenshot-C-C++ - rgbwebcam-src-rgbwebcam.cpp - Eclipse SDK

When I was writing a simple example of OpenCV below, an repeating error happened as ‘VIDIOC_QUERYMENU:Invalid argument’.

Is this because the Qt for drawing the output of openCV?

The code

The code that caused the above error is like this:

#include “opencv2/highgui/highgui.hpp”
#include “opencv2/core/core.hpp”
#include “opencv2/imgproc/imgproc.hpp”
#include “opencv2/video/video.hpp”
using namespace cv;
using namespace std;
int main(int argc, char *argv[])
VideoCapture cap(0);
Mat frame;
cap >> frame;
if(waitKey(30) == 27) break;
return 0;

The error happened when initialising the webcam, but the webcam was working fine even though the errors were given in the console window.

The fix

From a post from stackoverflow, this problem was

with Qt handling its own event loop and thus the event loop of OpenCV is starved and never get run.

The way to get them to work together is quite simple: Display your OpenCV as a QPixmap (by convert your image to QImage then use QLabel to display it). Then add this QLabel to your QWidget. Your QWidget can either be embedded or become the main widget of your QApplication.

But it may not be so easy to get rid of, as other posts also mentioned that

You can’t mix openCV’s control of the event loop and qt’s app.exec

Either use the Qt flavour of the cvNamedWindow, or simple grab images from openCV and display them in a QLabel. Or better inherit from QWidget and write your own QImage painter

void OpencvWidget::paintEvent(QPaintEvent*)
//m_win is the window size
QPainter p(this);


The best way to fix ‘VIDIOC_QUERYMENU:Invalid argument’

I have faced a similar problem recently (displaying webcam information using OpenCV and Qt as the final GUI). The best way that I find out to play the video (which is basically a set of images) is to use a GLWidget.

Author: Andol Li

A HCI researcher, a digital media lecturer, an information product designer, and a python/php/java coder.

4 Comments On “ The error of ‘VIDIOC_QUERYMENU: Invalid argument’”

  1. I’m new to this and that’s also exactly the code that I have with the same error. But I don’t know anything about Qt and I don’t have it in my program yet. So how does the code look without the error? I can’t get much from the ‘fixes’. Thanks.

  2. I knew that the error “VIDIOC_QUERYMENU: Invalid argument” was due to an incompatibility between the webcam and the driver.
    This error also appears to me on a program where I can not display the image. Do you know why?

    • @Elia
      I remembered when I did above codes the alarm appeared but the videos were still showing.
      more details may be needed to diagnose your situation, as in this stage I cannot say something useful.

  3. What i ddo not understood is in reality how you’re
    not really a lot more well-favored than you might be now.
    You are very intelligent. You understand therefore
    considerably when it comes to thks subject, produced me in my view iimagine it from numerous various
    angles. Itss like women and men aren’t involved unless it iss somethiung to accomplish with Woman gaga!
    Yoour individual stuffs great. All the time care for iit up!

Leave a comment to
Due to technical adjustments, the comment function is shortly closed and will be re-openning soon. Thanks.

Copyrights 2006-2018 © All rights reserved
Theme Tree2, re-designed by Andol Li, powered by WordPress and Bootsrap
WWW.ANDOL.ME | 浙ICP备15040508号-1
公安备案图标 浙公网安备33010602004018号
Back to top