Solved Opening a .py script from Qt (not running) in the default/user defined editor
-
Hello,
I want to open a python script from withing Qt.
The file should not be executed, it just should be opened with the default python-editor the user has installed.
Or as alternative the user should be able to specify the path to the editor to open the file with.How would you typically do this?
-
@gde23 said in Opening a .py script from Qt (not running) in the default/user defined editor:
The file should not be executed, it just should be opened with the default python-editor the user has installed.
Sounds like a job for
QDesktopServices::openUrl()
: https://doc.qt.io/qt-5/qdesktopservices.html#openUrlThis relies on the user configuring the OS to launch the editor when the user double-clicks the .py file on the desktop or file viewer app (e.g. Windows Explorer, Nautilus)
-
@JKSH Thanks for the quick reply. I also though about QDesktopSevice, but will this work?
Since when I click a python scrip on my system it gets executed and not opened in any editor?
And what would be the way if the user has explicitly specified a path to the editor to use? -
@gde23 said in Opening a .py script from Qt (not running) in the default/user defined editor:
when I click a python scrip on my system it gets executed and not opened in any editor?
And what would be the way if the user has explicitly specified a path to the editor to use?Ah, OK. In that case, you can use
QProcess
to launch the editor application and pass the .py file as an argument:QProcess proc; proc.startDetached("C:/Program Files (x86)/Notepad++/notepad++.exe", {"D:\\Project\\src\\hello.py"});
-
@JKSH Thanks a lot, that works the way I need it.
I also noticed that QDesktopService will still open the file in the editor (even when its executable and clicking calls python)