Qt and openCV on GNOME incompatibility
-
Sorry for annoying you with a problem which may not be a Qt issue at all - but maybe you can give me a hint.
Using Qt 5.15 on ubuntu 18.04LTS with GNOME desktop my application links openCV 4.5.1-pre 1 (freshly compiled from source on this machine). When I try to open a QColorDialog like withQColor newcol=QColorDialog::getColor(startCol, this, tr("Text Color"), QColorDialog::DontUseNativeDialog);
I get a bunch of GTK error messages on the console:
(Indexer:5035): GLib-GObject-WARNING **: 11:31:36.386: cannot register existing type 'GtkWidget' (Indexer:5035): GLib-GObject-WARNING **: 11:31:36.386: cannot add class private field to invalid type '<invalid>' (Indexer:5035): GLib-GObject-WARNING **: 11:31:36.386: cannot add private field to invalid (non-instantiatable) type '<invalid>' (Indexer:5035): GLib-GObject-CRITICAL **: 11:31:36.386: g_type_add_interface_static: assertion 'G_TYPE_IS_INSTANTIATABLE (instance_type)' failed (Indexer:5035): GLib-GObject-WARNING **: 11:31:36.386: cannot register existing type 'GtkBuildable' (Indexer:5035): GLib-GObject-CRITICAL **: 11:31:36.386: g_type_interface_add_prerequisite: assertion 'G_TYPE_IS_INTERFACE (interface_type)' failed (Indexer:5035): GLib-CRITICAL **: 11:31:36.386: g_once_init_leave: assertion 'result != 0' failed (Indexer:5035): GLib-GObject-CRITICAL **: 11:31:36.386: g_type_add_interface_static: assertion 'G_TYPE_IS_INSTANTIATABLE (instance_type)' failed (Indexer:5035): GLib-GObject-CRITICAL **: 11:31:36.386: g_type_register_static: assertion 'parent_type > 0' failed (Indexer:5035): GLib-GObject-WARNING **: 11:31:36.386: cannot add private field to invalid (non-instantiatable) type '<invalid>'
and the application user interface is permanently broken. (It does not crash but no dialog is shown and you cannot interact with the app anymore, have to kill it)
This happens, not matter if I ask for the native dialog (omitting the DontUseNativeDialog, double negation :-) or the Qt styled dialog.
If I remove all openCV code which references libopencv_highgui (e.g.cv::namedWindow
) it works nicely, both in Qt style and native style.
Although I cannot prove it anymore I am quite sure that exactly the same code worked with Qt 5.7.
Strange observation: For the GTK interface to break it is enough to link against libopencv_highgui, without actively executing any code from the openCV lib. Maybe there is some static initialization in the openCV libs which is executed from compiler generated startup code.
Linking against libopencv_core alone is no problem.
The remaining app, except for the QColorDiaolg, works fine (and I use a lot of Qt stuff there). The openCV code also works fine and can use GTK+. (I can open openCV output windows which obviously use a direct GTK interface and they work fine.)Any ideas highly appreciated.
-
Since it breaks at the ColorDialog, which has nothing to do with openCV or whatever might suggest that it is some memory issue.
can you show the output when you run the application with valgring attached, so we can see if there are any invalid memory writes somewhere?
valgrind --leak-check=full ./yourBinary
-
See edit above - linking alone does NOT break the app, the code has to contain a reference to
cv::namedWindow
(so that -lopencv_highgui is actually referenced in the executable) in order to create the problem. Execution of this function is not required.Well, valgrind doesn't seem helpful here. Since the application stalls after the GTK issue, I have to kill it which also terminates the valgrind output. Otherwise it would hang forever. The debug output in line 6 and following is OK and as expected (generated through qDebug()<<...)
==9732== Memcheck, a memory error detector ==9732== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==9732== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info ==9732== Command: ./Indexer ==9732== dockwidfactory: registring DockWid "dwid_table" true dockwidfactory: registring DockWid "dwid_image" true dockwidfactory: registring DockWid "dwid_sources" true dockwidfactory: registring DockWid "dwid_images" true dockwidfactory: registring DockWid "dwid_tags" true dockwidfactory: registring DockWid "dwid_search" true dockwidfactory: registring DockWid "dwid_tagedit" true Gtk-Message: 14:19:50.621: Failed to load module "canberra-gtk-module" connectAll "DataContainer" "dwid_image" imageActionGSig(int,ImageAction) "dwid_images" sourceSelectedSig(int) "dwid_images" imageActionGSig(int,ImageAction) "dwid_search" querySelectedSig(void*) "dwid_sources" sourceSelectedSig(int) "dwid_tags" imageActionGSig(int,ImageAction) connectAll "dwid_image" "dwid_images" imageActionGSig(int,ImageAction) "dwid_tags" imageActionGSig(int,ImageAction) connectAll "dwid_images" "dwid_image" imageActionGSig(int,ImageAction) "dwid_search" querySelectedSig(void*) "dwid_sources" sourceSelectedSig(int) "dwid_tags" imageActionGSig(int,ImageAction) connectAll "dwid_search" "dwid_tags" labelActionGSig(int,LabelAction) connectAll "dwid_sources" "dwid_image" imageActionGSig(int,ImageAction) "dwid_images" sourceSelectedSig(int) "dwid_images" imageActionGSig(int,ImageAction) "dwid_search" querySelectedSig(void*) "dwid_tags" imageActionGSig(int,ImageAction) No such Source: 0 "select type, val from sources where pk=0" QSqlError("", "", "") connectAll "dwid_tagedit" connectAll "dwid_tags" "dwid_image" imageActionGSig(int,ImageAction) "dwid_images" imageActionGSig(int,ImageAction) "dwid_tagedit" tagsChangedSig() (Indexer:9732): GLib-GObject-WARNING **: 14:20:07.634: cannot register existing type 'GtkWidget' (Indexer:9732): GLib-GObject-WARNING **: 14:20:07.636: cannot add class private field to invalid type '<invalid>' (Indexer:9732): GLib-GObject-WARNING **: 14:20:07.636: cannot add private field to invalid (non-instantiatable) type '<invalid>' (Indexer:9732): GLib-GObject-CRITICAL **: 14:20:07.637: g_type_add_interface_static: assertion 'G_TYPE_IS_INSTANTIATABLE (instance_type)' failed (Indexer:9732): GLib-GObject-WARNING **: 14:20:07.638: cannot register existing type 'GtkBuildable' (Indexer:9732): GLib-GObject-CRITICAL **: 14:20:07.638: g_type_interface_add_prerequisite: assertion 'G_TYPE_IS_INTERFACE (interface_type)' failed (Indexer:9732): GLib-CRITICAL **: 14:20:07.639: g_once_init_leave: assertion 'result != 0' failed (Indexer:9732): GLib-GObject-CRITICAL **: 14:20:07.639: g_type_add_interface_static: assertion 'G_TYPE_IS_INSTANTIATABLE (instance_type)' failed (Indexer:9732): GLib-GObject-CRITICAL **: 14:20:07.640: g_type_register_static: assertion 'parent_type > 0' failed (Indexer:9732): GLib-GObject-WARNING **: 14:20:07.640: cannot add private field to invalid (non-instantiatable) type '<invalid>'
I also prepared a valgrind output of the working version (without openCV). It's quite a verbose output with tons of framework related, tiny mem-leaks, except for one 1k leak in my code which I don't understand. Some of this leaked data may belong to a singleton where orphaned mallocs don't hurt that much. If you think it is useful, I can upload it to some file share.
-
Hi,
IIRC OpenCV has a Qt backend, did you use your system a Qt or your 5.15 when building it ? There might be some clashes going on.
What are you using in OpenCV ?
-
Hi,
IIRC OpenCV has a Qt backend, did you use your system a Qt or your 5.15 when building it ? There might be some clashes going on.
What are you using in OpenCV ?
@SGaist
The cmake output of openCV did not mention any Qt. (And if it tried to access it straight forward it would fail because /usr/bin/qmake points to a defunct Qt4: "qmake: could not exec '/usr/lib/x86_64-linux-gnu/qt4/bin/qmake': No such file or directory")It mentions GTK+ in version 2.24.32 - does this indicate any conflict with Qt5.15?
I do transformation of images (FFTs, convolutions, filters, general math) in openCV and use the built in openCV output windows. Maybe I could work around this problem if I avoid all references to libopencv_highgui - could be a last-resort solution but would require some re-write of code which worked well in Qt 5.7 :-(
-- General configuration for OpenCV 4.5.1-pre ===================================== -- Version control: 4.5.0-249-g7521f207b1 -- -- Extra modules: -- Location (extra): /opt/opencv_contrib/modules -- Version control (extra): 4.5.0-47-g960714d4 -- -- Platform: -- Timestamp: 2020-11-27T21:11:33Z -- Host: Linux 5.4.0-54-generic x86_64 -- CMake: 3.10.2 -- CMake generator: Unix Makefiles -- CMake build tool: /usr/bin/make -- Configuration: RELEASE -- -- CPU/HW features: -- Baseline: SSE SSE2 SSE3 -- requested: SSE3 -- disabled: AVX -- Dispatched code generation: SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX -- requested: SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX -- SSE4_1 (15 files): + SSSE3 SSE4_1 -- SSE4_2 (1 files): + SSSE3 SSE4_1 POPCNT SSE4_2 -- FP16 (0 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX -- AVX (4 files): + SSSE3 SSE4_1 POPCNT SSE4_2 AVX -- AVX2 (29 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 -- AVX512_SKX (4 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX -- -- C/C++: -- Built as dynamic libs?: YES -- C++ standard: 11 -- C++ Compiler: /usr/bin/c++ (ver 7.5.0) -- C++ flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG -- C++ flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG -- C Compiler: /usr/bin/cc -- C flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG -DNDEBUG -- C flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -g -O0 -DDEBUG -D_DEBUG -- Linker flags (Release): -Wl,--gc-sections -Wl,--as-needed -- Linker flags (Debug): -Wl,--gc-sections -Wl,--as-needed -- ccache: NO -- Precompiled headers: NO -- Extra dependencies: dl m pthread rt -- 3rdparty dependencies: -- -- OpenCV modules: -- To be built: aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking video videoio videostab xfeatures2d ximgproc xobjdetect xphoto -- Disabled: world -- Disabled by dependency: - -- Unavailable: alphamat cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv hdf java js julia matlab ovis python2 python3 sfm ts viz -- Applications: apps -- Documentation: NO -- Non-free algorithms: NO -- -- GUI: -- GTK+: YES (ver 2.24.32) -- GThread : YES (ver 2.56.4) -- GtkGlExt: NO -- -- Media I/O: -- ZLib: /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.11) -- JPEG: /usr/lib/x86_64-linux-gnu/libjpeg.so (ver 80) -- WEBP: libwebp (ver encoder: 0x020f) -- PNG: /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.6.34) -- TIFF: build (ver 42 - 4.0.10) -- JPEG 2000: build (ver 2.3.1) -- OpenEXR: /usr/lib/x86_64-linux-gnu/libImath.so /usr/lib/x86_64-linux-gnu/libIlmImf.so /usr/lib/x86_64-linux-gnu/libIex.so /usr/lib/x86_64-linux-gnu/libHalf.so /usr/lib/x86_64-linux-gnu/libIlmThread.so (ver 2_2) -- HDR: YES -- SUNRASTER: YES -- PXM: YES -- PFM: YES -- -- Video I/O: -- DC1394: YES (2.2.5) -- FFMPEG: YES -- avcodec: YES (57.107.100) -- avformat: YES (57.83.100) -- avutil: YES (55.78.100) -- swscale: YES (4.8.100) -- avresample: YES (3.7.0) -- GStreamer: YES (1.14.5) -- -- Parallel framework: TBB (ver 2020.2 interface 11102) -- -- Trace: YES (with Intel ITT) -- -- Other third-party libraries: -- Lapack: NO -- Custom HAL: NO -- Protobuf: build (3.5.1) -- -- Python (for build): /usr/bin/python2.7 -- -- Java: -- ant: NO -- JNI: NO -- Java wrappers: NO -- Java tests: NO -- -- Install to: /usr/local -- ----------------------------------------------------------------- -- -- Configuring done
-
I am not quite sure that spining both Qt and GTK's event loop in the same binary will work. Qt has a GTK backend but it still pilots the event loop.
I would try to re-build OpenCV but with Qt support activated to see if things go better.
-
I am not quite sure that spining both Qt and GTK's event loop in the same binary will work. Qt has a GTK backend but it still pilots the event loop.
I would try to re-build OpenCV but with Qt support activated to see if things go better.
@SGaist
The more I think about this setup the more I wonder why it ever worked...
Funny thing is that running two event loops (one for Qt GUI an another for openCV GUI) works without any noticeable problems as long as you don't use QColorDialog.
Anyway, the look and feel will be better if the complete GUI comes from Qt. Transferring a cv::Mat to a QImage is not that difficult usingQImage(const uchar *data, ...
. And good bye libopencv_highgui. I'll mark the thread as solved, thanks for your input. -
@SGaist
The more I think about this setup the more I wonder why it ever worked...
Funny thing is that running two event loops (one for Qt GUI an another for openCV GUI) works without any noticeable problems as long as you don't use QColorDialog.
Anyway, the look and feel will be better if the complete GUI comes from Qt. Transferring a cv::Mat to a QImage is not that difficult usingQImage(const uchar *data, ...
. And good bye libopencv_highgui. I'll mark the thread as solved, thanks for your input.@stryga42 I would guess it works as long as the two eventloops do not interfere with each other. Calling the QColorDialog (or QFileDialog) static functions most likely call the Window-Manager specific versions of these dialogs which is a GTK one in your case so things get screwed up.
-
@stryga42 I would guess it works as long as the two eventloops do not interfere with each other. Calling the QColorDialog (or QFileDialog) static functions most likely call the Window-Manager specific versions of these dialogs which is a GTK one in your case so things get screwed up.
@Christian-Ehrlicher
Well, the problem pops up even if I callQColor newcol=QColorDialog::getColor(colorText, this, tr("Text and Frame Color"), QColorDialog::DontUseNativeDialog);
Actually I always did it this way - the native GNOME color picker is "very basic". I did not check the Qt source if GTK is initialized (but never opened) even if DontUseNativeDialog is specified.