Please nominate your Qt Champions for 2021!

Unable to use QtQuick Controls 2 with Pyside 2

  • I have set up:

    Python 3.5.3 virtual environment
    Compiled the Pyside 2 commit fafd92f428d51bdd56c90a73149c441773dd9155 (as the latest 2 commits were having issues with missing qrandomgenerator files).

    The compile was done with Qt 5.9.3, MSVC2015 x64, and cmake 3.10.1

    I'm trying to set this up to start using QML, and more specifically Material Style. However it seems that when I run my application, if the QML imports QtQuick.Controls 2.0 or later, engine.rootObjects() returns an empty list. I can import QtQuick.Controls versions 1.0 - 1.5. Did I miss something when compiling? or is there something wrong with my code?

    The code is as follows:


    import sys
    from PySide2 import QtGui
    from PySide2 import QtQml
    app = QtGui.QGuiApplication(sys.argv)
    engine = QtQml.QQmlApplicationEngine()
    ctx = engine.rootContext()
    ctx.setContextProperty("qmlapp", engine)
    win = engine.rootObjects()[0]


    import QtQuick 2.9
    import QtQuick.Controls 2.2
    ApplicationWindow {

    I grabbed those version numbers from the documentation for Qt Quick Controls 2.

  • I found the issue was I need QT bin in my path. Running the following corrected the issue:

    (venv35) C:\my\project\dir\>set PATH=C:\Qt\5.9.3\msvc2015_64\bin;%PATH%

Log in to reply