[PyQt] Problem loading qml when pyqtdeployed

Phil Thompson phil at riverbankcomputing.com
Tue Jan 27 17:05:10 GMT 2015

On 09/01/2015 5:19 pm, bootch at nc.rr.com wrote:
> In short:
> qmlUrl=QUrl.fromLocalFile(QFileInfo(__file__).path() +
> "/appPackage/qml/toolBar.qml")
> quickView.setSource(qmlUrl)
> doesn't work when pyqtdeployed, although it works when invoked from
> Python.  Also, I can load icons using similar construct (without
> wrapping in QUrl().  I don't see a way to load the quickview without
> calling QUrl() ).
> The error from Qt is:
> 'file:///home/bootch/pensoolpyqtdeploy/:/appPackage/qml/toolBar.qml:
> File not found'
> And qmlUrl.toString() is: 'file::/appPackage/qml/toolBar.qml'
> both of which seem garbled to me.
> I put a small example Eclipse project including the .pdy file at
> https://github.com/bootchk/testQmlFromResources.git
> Another strangeness is that invoked from Python, for an icon
> '/images/foo.png' works but for qml '/qml/toolBar.qml' does not work.
> Only '/appPackage/qml/toolBar.qml' works, even though the qml and
> images directory are at the same level in the directory structure.

URLs referencing embedded files (ie. those whose path starts with ':') 
need to be prefixed with qrc: rather than file:. fromLocalFile() should 
handle this automatically - but it doesn't.

The following should work...

root = QFileInfo(__file__).absolutePath()
root_url = 'qrc:' if root.startswith(':') else root

url = QUrl(root_url + '/appPackage/qml/toolBar.qml')


More information about the PyQt mailing list