[PyQt] Errors without 'import "."' in QML files

Louis Simons lousimons at gmail.com
Thu Dec 8 02:34:15 GMT 2016


I have been trying to learn PyQt5 by migrating an application from Kivy to
a QtQuick/Python hybrid. I'm finally starting to understand the
architecture a little better (I should have read the C++ docs sooner), but
I've been running into a little weirdness. In the repository at
https://github.com/superlou/snowman-qt-client, my root QML file is app.qml,
which requires the following imports to use my custom registered types:

import Snowman 1.0
import "components"

I've been having a hard time finding examples of QML projects beyond
single-file examples, but since my components are in the "components"
directory, it didn't seem too strange to need to explicitly tell QML where
the components in the Snowman namespace were. However, if I leave off the
explicit imports in MainBus.qml and MainBusButton.qml, I get lots of errors
about undefined types and recursive definitions. This seems to be resolved
by using something like the following:

import Snowman 1.0
import "."

I haven't found any examples where 'import "."' has been required, and my
understanding was that QML should look in the same directory for siblings
automatically. The application seems to operate normally with the import
scheme shown above, but this smells funny, and I wanted to make sure I'm
understanding the proper way to structure a large project before I bake an
anti-patten into the code. Is there a better way to handle this?

Thank you,
Louis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20161208/f3426e91/attachment.html>


More information about the PyQt mailing list