Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Opening a .py script from Qt (not running) in the default/user defined editor
Forum Updated to NodeBB v4.3 + New Features

Opening a .py script from Qt (not running) in the default/user defined editor

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 353 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • gde23G Offline
    gde23G Offline
    gde23
    wrote on last edited by
    #1

    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?

    JKSHJ 1 Reply Last reply
    0
    • gde23G gde23

      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?

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      @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#openUrl

      This 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)

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      3
      • gde23G Offline
        gde23G Offline
        gde23
        wrote on last edited by gde23
        #3

        @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?

        JKSHJ 1 Reply Last reply
        0
        • gde23G gde23

          @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?

          JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          @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"});
          

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          4
          • gde23G Offline
            gde23G Offline
            gde23
            wrote on last edited by
            #5

            @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)

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved