cv::namedWindow() with Qt support crashes when used in another Qt app (Patch #919)
Description
When using the function cv::namedWindow() with compiler-flag WITH_QT in a project that uses Qt, namedWindow() will crash if there is already another QApplication instance. The failed assertion is:
#!C Q_ASSERT_X(!self, "QCoreApplication", "there should be only one application object");
This is caused in file [source:trunk/opencv/modules/highgui/src/window_QT.cpp:#L441 highgui/window_QT.cpp, line 441]. In this line, a new QApplication object is created, even if one already exists. This happens in projects that create their own QApplication and event loop, and then want to use cv::namedWindow (for later cv::imshow or whatever reason).
Affected version: OpenCV 2.2 and current trunk from SVN
Tested on: Windows 7 Prof. 32bit, Visual Studio 2008, OpenCV 2.2, options WITH_QT and WITH_QT_OPENGL
Code to reproduce:
#!C #include <QApplication> #include "opencv2/core/core.hpp" #include "opencv2/highgui/highgui.hpp" int main(int argc, char *argv[]) { QApplication app(argc, argv); cv::namedWindow("test"); // CRASH! // it doesn't matter if namedWindow is called now // or later inside the event loop... return app.exec(); }
The same problem is described in http://tech.groups.yahoo.com/group/OpenCV/message/76941 . Although the resolutions and workarounds described there work, they don't solve the original problem: At the moment, you cannot use HighGUI with Qt backend in your own Qt applications.
I included a patch to fix this. It simply doesn't create a new QApp instance, if one already exists. It works in my environment. It will however cause problems when cvStartLoop is used for multi-threading (see comments), but that is not recommended right now anyway (see comments there, too).
Could somebody apply the patch, or can I commit the changes myself?
Regards, Linus Atorf
Associated revisions
Qt: fixed using of OpenCV in another Qt app (patch #919)
Merge pull request #919 from abidrahmank:2.4
Merge remote-tracking branch 'origin/2.4'
Pull requests:
#943 from jet47:cuda-5.5-support
#944 from jet47:cmake-2.8.11-cuda-fix
#912 from SpecLad:contributing
#934 from SpecLad:parallel-for
#931 from jet47:gpu-test-fixes
#932 from bitwangyaoyao:2.4_fixBFM
#918 from bitwangyaoyao:2.4_samples
#924 from pengx17:2.4_arithm_fix
#925 from pengx17:2.4_canny_tmp_fix
#927 from bitwangyaoyao:2.4_perf
#930 from pengx17:2.4_haar_ext
#928 from apavlenko:bugfix_3027
#920 from asmorkalov:android_move
#910 from pengx17:2.4_oclgfft
#913 from janm399:2.4
#916 from bitwangyaoyao:2.4_fixPyrLK
#919 from abidrahmank:2.4
#923 from pengx17:2.4_macfix
Conflicts:
modules/calib3d/src/stereobm.cpp
modules/features2d/src/detectors.cpp
modules/gpu/src/error.cpp
modules/gpu/src/precomp.hpp
modules/imgproc/src/distransform.cpp
modules/imgproc/src/morph.cpp
modules/ocl/include/opencv2/ocl/ocl.hpp
modules/ocl/perf/perf_color.cpp
modules/ocl/perf/perf_imgproc.cpp
modules/ocl/perf/perf_match_template.cpp
modules/ocl/perf/precomp.cpp
modules/ocl/perf/precomp.hpp
modules/ocl/src/arithm.cpp
modules/ocl/src/canny.cpp
modules/ocl/src/filtering.cpp
modules/ocl/src/haar.cpp
modules/ocl/src/hog.cpp
modules/ocl/src/imgproc.cpp
modules/ocl/src/opencl/haarobjectdetect.cl
modules/ocl/src/pyrlk.cpp
modules/video/src/bgfg_gaussmix2.cpp
modules/video/src/lkpyramid.cpp
platforms/linux/scripts/cmake_arm_gnueabi_hardfp.sh
platforms/linux/scripts/cmake_arm_gnueabi_softfp.sh
platforms/scripts/ABI_compat_generator.py
samples/ocl/facedetect.cpp
History
Updated by Linus Atorf almost 14 years ago
Any news on this? I've been using the patch since I posted this...
Updated by Linus Atorf almost 14 years ago
Maybe if I modify the status to defect?
Updated by Ilya Lysenkov over 13 years ago
- Status deleted (
Open)
Updated by Ilya Lysenkov over 13 years ago
Thank you a lot for detailed report and patch. I've applied it in -r5513 (trunk) with minor changes.
- Status set to Done
- (deleted custom field) set to fixed
Updated by Andrey Kamaev over 12 years ago
- Tracker changed from Bug to Patch
- Category changed from highgui-images to highgui-gui