Unsolved Qt project using matplotlib fails with "cannot create a QWidget without QApplication error
-
Re: QWidget: Cannot create a QWidget without QApplication - OpenCV imshow() 2.4.13 ?
I figure someone else will eventually run into this, and I am just documenting whazzup. Those of us who are into scientific projects frequently need to use matplotlib to create plots, but matplotlib is a python library. Which is okay if you don't mind using Qt for Python, but for a few years now I have used C++ as my language of choice. Instead of using Qt for Python, it is not that difficult to take advantage of
python's built-in Python/C API to embed a python interpreter in your C++ code. And, since matplotlib can save plots as PNG files, you can then present them in QML Images. But, at some version of Qt, my previous Way of embedding matplotlib python code in my Qt/QML apps began failing with a "cannot create QWIdget without QApplication" error. The now closed topic which this topic references pointed out that the fix for this error is to add "widgets" to the QT += statement in your qmake .pro file, and to use QApplication in your main.cpp. If someone wishes, I'll put up an example of what I am talking about on github, but it might not be "Hello World" -esque due to my multi-lingual coding style which mixes C++, python, QML, javascript, OpenCL, GLSL, and whatever else I need at the time.