QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?
-
@wrosecrans said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:
@R-P-H said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:
QApplication only works with a GUI project.
If you want to show a GUI window, you are making a GUI project, surely?
No, it's a console project. I just wanted a pop up window for test purposes. For example, to check if an image is loading correctly. As I said, it did work before. I can't say for sure what caused it to stop working.
-
@R-P-H said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:
QApplication only works with a GUI project.
I'll bite. How are windows supposed to be created if you're not running X?
-
@kshegunov said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:
@R-P-H said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:
QApplication only works with a GUI project.
I'll bite. How are windows supposed to be created if you're not running X?
Well Visual Studio has no problem doing it. I have made countless win32 console applications inside of Visual Studio (where the only output is a terminal window) and imshow() works perfectly.
It's not like I'm trying to open the image inside a Qt GUI window. It's an OpenCV image window that should open separately. As I said, there is no question that it was working before.
-
@R-P-H said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:
It's not like I'm trying to open the image inside a Qt GUI window.
Well apparently you are.
It's an OpenCV image window that should open separately.
Which I suspect uses Qt as a backend and it rightfully complains.
As I said, there is no question that it was working before.
This doesn't mean anything if you don't follow the rules.
QWidget
goes withQApplication
. To that end what's the problem of usingQApplication
and still use the console for input and output? -
@kshegunov said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:
@R-P-H said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:
It's not like I'm trying to open the image inside a Qt GUI window.
Well apparently you are.
It's an OpenCV image window that should open separately.
Which I suspect uses Qt as a backend and it rightfully complains.
As I said, there is no question that it was working before.
This doesn't mean anything if you don't follow the rules.
QWidget
goes withQApplication
. To that end what's the problem of usingQApplication
and still use the console for input and output?The traditional terminal window is suppressed when using a GUI project and I have no need for a GUI window of any kind which gets created by default.
-
I've just confirmed that this will work on my system, Qt 5.10.0, MSVC 2017, OpenCV 3.1.0 (?), so it's not a matter of QCoreApplication vs QApplication.
using namespace cv; using namespace std; int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); Mat image; image = imread("c:\\tmp\\triangle_red.png", CV_LOAD_IMAGE_COLOR); imshow("Frame", image); return a.exec(); }
-
@R-P-H said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:
The traditional terminal window is suppressed when using a GUI project and I have no need for a GUI window of any kind which gets created by default.
I didn't say to change your project type. I just said to replace
QCoreApplication
withQApplication
. -
@mranger90 said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:
I've just confirmed that this will work on my system, Qt 5.10.0, MSVC 2017, OpenCV 3.1.0 (?), so it's not a matter of QCoreApplication vs QApplication.
using namespace cv; using namespace std; int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); Mat image; image = imread("c:\\tmp\\triangle_red.png", CV_LOAD_IMAGE_COLOR); imshow("Frame", image); return a.exec(); }
Thanks for confirming. As I suspected, there is some other underlying problem on my system. Either from an update or from adding a 2nd compiler kit.
-
@kshegunov said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:
@R-P-H said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:
The traditional terminal window is suppressed when using a GUI project and I have no need for a GUI window of any kind which gets created by default.
I didn't say to change your project type. I just said to replace
QCoreApplication
withQApplication
.Sorry, I didn't realise you meant just changing that. Changing it gives the error that it's not found.
-
You need to add
QT += widgets
to your .pro file to useQApplication
. -
@R-P-H said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:
Changing it gives the error that it's not found.
Can you show the project file (*.pro)? I suspect you did not add
QT = core gui widgets
to it. -
@SGaist said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:
You need to add
QT += widgets
to your .pro file to useQApplication
.@kshegunov said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:
@R-P-H said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:
Changing it gives the error that it's not found.
Can you show the project file (*.pro)? I suspect you did not add
QT = core gui widgets
to it.QT -= gui CONFIG += c++11 console CONFIG -= app_bundle QT += widgets DEFINES += QT_DEPRECATED_WARNINGS SOURCES += \ main.cpp
If I add either
QT += widgets
orQT = core gui widgets
to the .pro file and replaceQCoreApplication
withQApplication
it works fine. It will not work withQCoreApplication
however. -
@R-P-H said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:
It will not work with QCoreApplication however.
QCoreApplication
does not perform the needed steps to initialize the runtime for creating widgets. So yes it shouldn't be possible to create widgets withQCoreApplication
; if it is, then you're using an undocumented behavior that's internal to the library, and it can stop working at any time without warning or crash. Warnings from the Qt library should be treated as errors in the user code. -
@kshegunov said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:
@R-P-H said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:
It will not work with QCoreApplication however.
QCoreApplication
does not perform the needed steps to initialize the runtime for creating widgets. So yes it shouldn't be possible to create widgets withQCoreApplication
; if it is, then you're using an undocumented behavior that's internal to the library, and it can stop working at any time without warning or crash. Warnings from the Qt library should be treated as errors in the user code.Alright thanks, at least I know how to get it to work now although I still find it strange that it was working before without having to use QApplication.
In terms of using QCoreApplication I was referring to @mranger90 post below:
@mranger90 said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:
I've just confirmed that this will work on my system, Qt 5.10.0, MSVC 2017, OpenCV 3.1.0 (?), so it's not a matter of QCoreApplication vs QApplication.
where he confirmed that it does work with QCoreApplication. Strange.
-
@R-P-H said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:
Alright thanks, at least I know how to get it to work now although I still find it strange that it was working before without having to use QApplication.
You may want to rise this issue with OpenCV developers - looks like it is some change on their side. The documentation for imshow() does not mention any GUI config requirements.
And if it worked before it may be a regression.
-
@sierdzio said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:
The documentation for imshow() does not mention any GUI config requirements.
It mentions that opencv will have a backend, and this is specified when building as well (
--with-qt
option), thus Qt requirements propagate through to opencv.And if it worked before it may be a regression.
I doubt it. I continue to claim that creating a widget, which is what apparently
imshow
does, is not supported withQCoreApplication
, never was and never will, regardless of whether it worked before, now or in the future.where he confirmed that it does work with QCoreApplication.
Before applying the patch update
5.10.1
. -
@kshegunov said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:
It mentions that opencv will have a backend, and this is specified when building as well (--with-qt option), thus Qt requirements propagate through to opencv.
Is Qt the only supported backend? If yes, then indeed requirements do propagate. If no, then it may be the case that OP is using Qt for his console app, but OpenCV uses other framework to construct the window.
Anyway, I don't know OpenCV so I'm only speculating.
-
@sierdzio said in QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?:
Is Qt the only supported backend?
This I don't know, I don't know or use opencv as well. To be honest OpenCV's documentation's a bit vague and somewhat suspicious on the matter.
OpenCV uses other framework to construct the window.
This conflicts with the code snippet and the runtime error the OP gets ... and the fix. Apparently opencv in that case uses Qt to create the widget for display.
-
Yep, you're right.