Opencv 2.4.0 with QT 4.7.4 and cvcreatebutton exception (Bug #1890)

Added by marc w almost 5 years ago. Updated over 3 years ago.

Status:Done Start date:2012-05-03
Priority:Normal Due date:
Assignee:Alexander Smorkalov % Done:


Target version:Next Hackathon
Affected version:2.4.6 (latest release) Operating System:Any
Difficulty: HW Platform:x86
Pull request:



I have compiled opencv with qt and opengl flag. now many of qt functions from the documentation are working but not the cvcreatebutton. it throws an exception (e.g see screenshot) the example from the documentation dont work.. evertime i use cvcreatebutton it fails.

my code:

void callBackR(int state, void *pointer){

int main(){



Unbenannt.JPG - visual 2010 german screenshot exception while debug (64.6 kB) marc w, 2012-05-03 10:39 pm


Updated by Andrey Kamaev almost 5 years ago

  • Category set to highgui-images

Updated by Andrey Kamaev over 4 years ago

  • Category changed from highgui-images to highgui-gui

Updated by Tim Sweet over 3 years ago


I've spent the last few hours tracking this bug down and finally went all the way back to the C interface source to figure it out. For context, here's the source of the old function cvCreateButton:

On lines 605-606 if no gui has been drawn yet it should produce a CV_Error, however all I get is a segmentation fault. The segmentation fault is actually raised on lines 611-618 (see justification below). I'm not sure how to fix this because if I call CV_Error(CV_StsNullPtr, "NULL guiReceiver (please create a window)") directly I get the correct error and the program terminates correctly.

Steps to reproduce the bug:
- Using OpenCV 2.4 on Linux, compiled from source (not sure if it affects other versions)
- Before opening any OpenGL windows (but regular windows can be opened, such as cv::namedWindow("output",CV_WINDOW_AUTOSIZE) ) make a call to:

cv::createButton("Button",ButtonCallback); //where ButtonCallback is prototyped as void Foo(int,void*)

- Get segmentation fault
- This can be pinpointed to lines 611-618 in the source by calling cv::createButton("Button",ButtonCallback,NULL,CV_PUSH_BUTTON,-10) which will try to create a button with invalid initial state -10, causing the function to immediately return 0 and not segfault.

If someone points me in the right direction I'd be happy to produce a pull request to fix this, I'm just not sure how to go about it..

  • Assignee deleted (Alexander Reshetnikov)

Updated by Tim Sweet over 3 years ago

I should be more specific: something along these lines has to happen in order to not get the segmentation fault. If this doesn't happen the expected behavior is to throw a CV_Error:

  • cv::namedWindow("name",CV_WINDOW_OPENGL);
  • cv::Mat image(cv::Size(1,1),CV_8UC1,cv::Scalar(0)); //any initialized Mat will do
  • cv::imshow("name",image);

Updated by Anna Kogan over 3 years ago

Hello Tim, thank you for debugging the issue!

Alexander, could you please take a look at this?

  • HW Platform set to x86
  • Operating System set to Any
  • Affected version set to branch '2.4'
  • Assignee set to Alexander Smorkalov

Updated by Alexander Smorkalov over 3 years ago

You can contribute your fixes using the instruction from "How to contribute" wiki page:

Updated by Alexander Smorkalov over 3 years ago

  • Target version set to Next Hackathon

Updated by Alexander Smorkalov over 3 years ago

I reproduce the problem with small sample:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <stdio.h>

void callBackR(int state, void *);

void callBackR(int state, void *)

int main(int, char**)
    cv::namedWindow("qqq", CV_WINDOW_OPENGL);
    cv::createButton("Button", callBackR);
    return 0;

Application fails not here, but inside QVector. Problem is cased by window_QT.cpp:1739

void CvWindow::enablePropertiesButton()

Updated by Alexander Smorkalov over 3 years ago

  • Pull request set to

Updated by Alexander Smorkalov over 3 years ago

  • Status changed from Open to Done
  • Affected version changed from branch '2.4' to 2.4.6 (latest release)

Also available in: Atom PDF