Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How to tell Qt/PySide2 where to look for the qt.conf file on Windows?
Forum Updated to NodeBB v4.3 + New Features

How to tell Qt/PySide2 where to look for the qt.conf file on Windows?

Scheduled Pinned Locked Moved Unsolved Qt for Python
pyside2
4 Posts 2 Posters 2.2k 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.
  • T Offline
    T Offline
    Tony32423
    wrote on last edited by
    #1

    When creating a QApplication or QCoreApplication Qt looks for the qt.conf file relative to the applicationFilePath. On Windows the applicationFilePath is always the path name of the actual executable (see qAppFileName in qcoreapplication_win.cpp).

    Usually this is fine as qt.conf is in the same folder as python.exe and the prefix and library paths are picked up from there.

    However, when embedding Python into another application this is a problem as the executable is no longer python.exe. Setting QT_PLUGIN_PATH is a partial solution as that gets the library paths set mostly correctly, but this doesn't solve the issue of some of the other paths not being set correctly (eg DataPath).

    Is there a way to tell Qt where to look for the qt.conf file? Or is there a way to set these other paths with some different environment variables or some other way before initializing the app?

    Thanks!

    T JonBJ 2 Replies Last reply
    0
    • T Tony32423

      When creating a QApplication or QCoreApplication Qt looks for the qt.conf file relative to the applicationFilePath. On Windows the applicationFilePath is always the path name of the actual executable (see qAppFileName in qcoreapplication_win.cpp).

      Usually this is fine as qt.conf is in the same folder as python.exe and the prefix and library paths are picked up from there.

      However, when embedding Python into another application this is a problem as the executable is no longer python.exe. Setting QT_PLUGIN_PATH is a partial solution as that gets the library paths set mostly correctly, but this doesn't solve the issue of some of the other paths not being set correctly (eg DataPath).

      Is there a way to tell Qt where to look for the qt.conf file? Or is there a way to set these other paths with some different environment variables or some other way before initializing the app?

      Thanks!

      T Offline
      T Offline
      Tony32423
      wrote on last edited by
      #2

      I have tried the "-qtconf" argument when constructing the app but that doesn't do the trick:

      from PySide2.QtWidgets import QApplication
      from PySide2.QtCore import QLibraryInfo
      
      # sys.executable is set to python.exe
      qtconf = os.path.join(os.path.dirname(sys.executable), "qt.conf")
      if not os.path.exists(qtconf):
         raise Exception("qt.conf file not found: %s" % qtconf)
      
      # create the app using the -qtconf argument
      app = QApplication(["-qtconf", qtconf])
      
      # these should be take from the qt.conf file
      print("PREFIX = %s" % QLibraryInfo.location(QLibraryInfo.PrefixPath))
      print("DATA = %s" % QLibraryInfo.location(QLibraryInfo.DataPath))
      

      This prints the following:

      PREFIX = C:/Users/filipe/miniconda3/conda-bld/qt_1598494811799/_h_env/Library
      DATA = C:/Users/filipe/miniconda3/conda-bld/qt_1598494811799/_h_env/Library
      

      which looks like the paths from when the Python packages were built.

      Something similar happens with PyQt5 in that it doesn't pick up the qt.conf file from the arguments, but it does at least default the locations to its own copy of the qt libs in its site-packages folder.

      Any suggestions of anything else to try greatly appreciated!

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Tony32423
        wrote on last edited by
        #3

        Building a resource containing "/qt/etc/qt.config" and using QResource.registerResource before creating the app works. This is ok but is a bit complicated and involves building the resource from Python with rcc. Still hoping for a simpler way!

        1 Reply Last reply
        0
        • T Tony32423

          When creating a QApplication or QCoreApplication Qt looks for the qt.conf file relative to the applicationFilePath. On Windows the applicationFilePath is always the path name of the actual executable (see qAppFileName in qcoreapplication_win.cpp).

          Usually this is fine as qt.conf is in the same folder as python.exe and the prefix and library paths are picked up from there.

          However, when embedding Python into another application this is a problem as the executable is no longer python.exe. Setting QT_PLUGIN_PATH is a partial solution as that gets the library paths set mostly correctly, but this doesn't solve the issue of some of the other paths not being set correctly (eg DataPath).

          Is there a way to tell Qt where to look for the qt.conf file? Or is there a way to set these other paths with some different environment variables or some other way before initializing the app?

          Thanks!

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Tony32423 said in How to tell Qt/PySide2 where to look for the qt.conf file on Windows?:

          Usually this is fine as qt.conf is in the same folder as python.exe

          I'm sorry I'm not providing any solution here, but this sounds awful! Why would a Qt configuration file be placed in the same directory of the general python.exe program?

          Something similar happens with PyQt5 in that it doesn't pick up the qt.conf file from the arguments, but it does at least default the locations to its own copy of the qt libs in its site-packages folder.

          This sounds much better. The qt.conf file should surely be placed somewhere inside Qt stuff.

          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