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 Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 2 Posters 458 Views 2 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.
  • april_heardA Offline
    april_heardA Offline
    april_heard
    wrote on 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
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on 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

      april_heardA 1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on 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

        april_heardA 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          How are you deploying your application ?

          april_heardA Offline
          april_heardA Offline
          april_heard
          wrote on 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
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on 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

            april_heardA 1 Reply Last reply
            1
            • SGaistS SGaist

              Do it the Python way:

              script_path = os.path.dirname(os.path.realpath(__file__))
              
              april_heardA Offline
              april_heardA Offline
              april_heard
              wrote on last edited by
              #5

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

              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