PDA

View Full Version : Embedding Python QFileDialog Issue



ewferg
11th December 2015, 22:43
Currently, I am developing a C++ GUI application using the Qt framework. Typically this application is driven by user mouse/keyboard input. However, we have recently built a python interface using PyQt so users can drive the application with simple python scripts. This means that we have to embed a python interpreter within our C++ application. In order to initialize the interpreter, we have simply been calling Py_Initialize() in our main.cpp function after setting up the main window and then calling Py_Finalize(); before the program exits. This seems to work without issues on both Mac and Linux platforms, but I seem to be running into problems on windows.

After Py_Initialize() has been called, user’s can open a file browser to pick a file of interest to read into the program. In the code, we use the QFileDialog::getOpenFileName static method to allow users to pick their file. However, on Windows, the program is crashing on this call. The program looks to be crashing on a call to PyDict_GetItem within the python library. I have created a super simple Qt GUI program which I have attached that exhibits the same crash. In order to run it, you need to have the Python 2.7 library installed on your machine in the location specified by the .pro file (or of course change the .pro file). C:/Python27/libs/python27.lib

Here are some additional specs that may be useful for diagnosing the problem:
Qt Framework Version: Qt 5.4.0
Python Version: 2.7.10
Building with Desktop Qt 5.4.0 MSVC2013 OpenGL 64bit Kit
Thank you in advance for your time!

Regards,