thp / pyotherside

Python Bindings for Qt 5 and Qt 6. Allows you to access a CPython 3 interpreter directly from your Qt QML user interface code.
https://thp.io/2011/pyotherside/
Other
364 stars 49 forks source link

Applicatíon crashes when Python is used in multiple QML files #82

Closed hit1001 closed 5 years ago

hit1001 commented 7 years ago

I am working with an application where i am using Pythoin interpreter in more than QML files. During debugging what i found out was that when i use only for single QML file it builds up UI and works fine. Moreover when used it in multiple files, the application crashes. I do not use PyQt binding too. I am just trying to build and run from Qt creator.

Also i have noticed that it works completely fine with qmlscene, and works with multiple files too. But i read that it is just for testing.

What could be the possible way to build it with multiple QML files?

Thanks.

thp commented 7 years ago

Could it be that it's something related to Qt Creator's QML debugging features? Especially if multiple Python {} objects work from qmlscene?

hit1001 commented 7 years ago

Maybe that could be the case, as the application already works if it is being used by qmlscene.

But the main question is that will that be a good idea to use an application using qmlscene for production to rather than using qmake and building and running or also having an executable file of it ?

thp commented 7 years ago

AFAIR there's a new qml command line (at least in recent Qt 5.x versions) that should work as a drop-in replacement for qmlscene and that is supposed to be used as "production" QML runtime.

See this: https://www.ics.com/blog/whole-shebang-running-qml-files-directly

niksabaldun commented 7 years ago

The qml utility is hardly an option for desktop systems, as there doesn't seem to be a way to set application icon (correct me if I am wrong). Does this crashing happen in debug build only, or in release as well?

hit1001 commented 7 years ago

It happens in debug as well as in release. Any by using qml in a file and make it as an executable does not really become a stand alone application. It then becomes a compulsion to install Qt first.

niksabaldun commented 7 years ago

That is too bad. I was considering using pyotherside for my project, but it seems I'll have to go with PyQt.

niksabaldun commented 7 years ago

@thp Is there any reason not to use a single Python object for the whole application? Or, to rephrase, can a single Python object in main window serve all application windows just as well as one Python object for each window?

thp commented 7 years ago

Yes, in fact that's how I use it, i create one Python {} QML object, usually with an ID of e.g. py and then use py.<something> anywhere (of course that object must be visible in the scope of the outer objects, but having it in the main window is usually the way to go).

hit1001 commented 7 years ago

@thp I actually tried implementing only one Python object for the main.qml file instead of using for every window. Earlier if Python object was only used by one window than the application would successfully build. But still it crashes even after using only in one window.