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

Cody Scott cody at perspexis.com
Thu Dec 8 14:36:47 GMT 2016


This is strange. You shouldn't need to import anything in
components/MainBus.qml to access MainBusButton {} since MainBusButton.qml
is in the components/ directory.

One thing is that you are registering MainBusButton in Python and it is
also registered when you import components. So it seems to me that you are
registering the same type twice.

But the component you are using has characteristics of both. And it is
working.

Let me know if you end up changing it.

On Wed, Dec 7, 2016 at 9:34 PM, Louis Simons <lousimons at gmail.com> wrote:

> 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
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20161208/5733117e/attachment.html>


More information about the PyQt mailing list