Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to specify the path to my main.qml file? (Python)
Forum Update on Monday, May 27th 2025

How to specify the path to my main.qml file? (Python)

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 2 Posters 443 Views
  • 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.
  • A Offline
    A Offline
    april_heard
    wrote on 19 Jan 2020, 05:20 last edited by
    #1

    My application consists of one python file, one qml file and one application icon. I am deploying it to KDE only, so I have no dependencies to be concerned with.

    How do I properly specify a path to both the QML file and the icon in my main.py file and avoid hard-coding this path?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 19 Jan 2020, 19:46 last edited by
      #4

      Do it the Python way:

      script_path = os.path.dirname(os.path.realpath(__file__))
      

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply 19 Jan 2020, 22:30
      1
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 19 Jan 2020, 06:28 last edited by
        #2

        Hi,

        How are you deploying your application ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        A 1 Reply Last reply 19 Jan 2020, 06:48
        0
        • S SGaist
          19 Jan 2020, 06:28

          Hi,

          How are you deploying your application ?

          A Offline
          A Offline
          april_heard
          wrote on 19 Jan 2020, 06:48 last edited by april_heard
          #3

          @SGaist said in How to specify the path to my main.qml file? (Python):

          Hi,

          How are you deploying your application ?

          I am open to suggestions. I was planning to use something like the "generic solution" mentioned here: https://doc.qt.io/qt-5/linux-deployment.html (which is to just use a shell script).

          One problem I face is how (in my main.py file) can I obtain the location of that file? QCoreApplication.applicationDirPath() does not do that on Linux. If I can get the location of my main.py file (while main is executing), I can then load my QML file and application icon.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 19 Jan 2020, 19:46 last edited by
            #4

            Do it the Python way:

            script_path = os.path.dirname(os.path.realpath(__file__))
            

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            A 1 Reply Last reply 19 Jan 2020, 22:30
            1
            • S SGaist
              19 Jan 2020, 19:46

              Do it the Python way:

              script_path = os.path.dirname(os.path.realpath(__file__))
              
              A Offline
              A Offline
              april_heard
              wrote on 19 Jan 2020, 22:30 last edited by
              #5

              @SGaist You are a true champion of this forum :-)

              1 Reply Last reply
              0

              1/5

              19 Jan 2020, 05:20

              • Login

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