Basically:
I have a python script I want to execute.
When I run my program, my build directory does not include the python script.
Therefore I can not find the file with QDir, unless I manually set it.
Am I supposed to get it so the .py file is included in my build directory? Or am I missing something here?
Qt does shadow building by default, meaning that it puts all the intermediate files and binaries it makes in a nearby folder called:
build-<target>-<compilier>-configuration
To be able to find a file, you need to be able to see if from the working directory
. The default working directory is the same as the build directory.
In my projects, I typically change the working directory to the same folder as my source files. To do this go to:
Projects > Run > Working Directory
Then browse to the folder with your code.
Now when you look for your file it will be there.
The other option is to use Qt's resource file system, where it packs your python script into your exe.
http://doc.qt.io/qt-5/resources.html
For that to work, first, create a new Qt resource file using file > new
, then add your script to a Qt Resource file. After it is added right click on it and click copy resource path
.
Then go to your line of code where you want to access the file and paste. You should see something like ":/my_script.py"
.
Hope that helps.