How do I set up Qt windows for OpenCV in Ubuntu ?

asked 2020-03-07 12:53:45 -0600

raisa_ gravatar image

updated 2020-03-11 01:03:57 -0600

Hi, I've been following an OpenCV tutorial from a book. Prior to it, I have OpenCV already installed on my machine. I'm working with OpenCV & C++ on a terminal and compile my program with CMake. Here's my Ubuntu & OpenCV version :

Ubuntu 18.04.4 LTS
OpenCV version : 4.2.0

In the book whenever they use imshow(), it shows a window with a toolbar and status bar on it, mine is not. And later on the next few chapters, they still use this toolbar for many purposes. After searching for a while, I found out that it is using Qt GUI. So, I went on to install Qt using these following codes :

sudo apt-get install qtcreator
sudo apt-get install qt5-default

And when I checked my Qt version, this is what I got :

$ qmake --version                                                                  
QMake version 3.1
Using Qt version 5.9.5 in /usr/lib/x86_64-linux-gnu

So, now I have Qt installed in my machine, but how do I integrate this with my OpenCV so I can use it on my programs other than putting highgui lib ? I encountered this error :

The library is compiled without QT support in function

I've been looking around online but still don't know how. Do I need to entirely uninstall OpenCV and compile it again with QT using CMake ?


Apparently there was no other way beside completely uninstall OpenCV and then compile & reinstalling it with QT. This is what I do :

  1. Uninstall OpenCV (already reinstalled 3 times)

    sudo apt-get purge '*opencv*'
    sudo find / -name "*opencv*" -exec rm -rf {} \;
  2. Cloning OpenCV and OpenCV contrib from Github, and during building with CMake, put WITH_QT = ON. here's the full set up that I used :

    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D WITH_TBB=ON \ 
    -D WITH_V4L=ON \ 
    -D WITH_QT=ON \ 
    -D OPENCV_EXTRA_MODULES_PATH=~/opencv_build/opencv_contrib/modules \

But why does I still get error on any project with QT on it (I have QT properties on my createButton function) even after I entirely reinstall, build and make OpenCV using WITH_QT=ON ? Does CMake failed to locate QT ? Here's the full exeption :

terminate called after throwing an instance of 'cv::Exception' what():  
OpenCV(4.2.0-dev) /home/raisa/opencv_build/opencv/modules/highgui/src/window.cpp:597:
error: (-213:The function/feature is not implemented)
The library is compiled without QT support in function 'createButton'

[2]    10467 abort (core dumped)  ./exerc13

Here's the function createButton that causing error

//Create buttons
createButton("Blur",  blurCallback,  NULL, QT_CHECKBOX, 0);
createButton("Grey",  greyCallback,  NULL, QT_RADIOBOX, 0);
createButton("RGB",   bgrCallback,   NULL, QT_RADIOBOX, 1);
createButton("Sobel", sobelCallback, NULL, QT_PUSH_BUTTON, 0);

Literally just because I have QT properties there and it's causing error "The library is compiled without QT support". Any advice ?


I read about explicit path definition for Qt integration instead of just putting WITH_QT=ON. So I decided to go with cmake-gui and ... (more)

edit retag flag offensive close merge delete



I don't know (I have no knowledge of the Qt-containing OpenCV). But there's always a possibility that you get a wrong error message for a problem in your code - bugs may cause weird behaviour. So, to check that possibility, you could show your code and where exactly you get the error. Someone might notice something.

mvuori gravatar imagemvuori ( 2020-03-10 17:06:47 -0600 )edit

@mvuori Sure, I've update my question !

raisa_ gravatar imageraisa_ ( 2020-03-11 01:06:18 -0600 )edit