32

I am a beginner in Qt-Quick. I am not aware of Qt which is a basis for QML. And also I'm not familiar with C++ which is again main supported language for both Qt and QML. I'm aware JS can do a lot of logic in QML layer itself. But if we need interactions with OS, then we have to use some base language. As I'm comfortable with Python, I m planning for "QML-JS-Python" combination.

So, My questions:

  1. For advanced Application and Game development Does Python & Qt-Quick do well hand in hand?
  2. Is my Combination Trio (QML-JS-Python) is good enough for this?
  3. And do I need to learn Qt for App development for coupling with Python from QML?
  4. If yes for Qust 3 then should I learn complete Qt or Only those few lines of code which stands as communication door between Python and QML?

Sorry If I'm dumb in posing these Questions. But I would like to take suggestions and opinions .

Edit: Any Limitations for this Combination QML-JS-Python

Thanks in Advance

inblueswithu
  • 953
  • 2
  • 18
  • 29
  • 1
    Why don't you just keep it to JS - one dynamic language is enough, plus JS has better performance than Python. For Qt you need C++ to extend QML and JS to bind QML components together. Python in this context is a redundant tool. – dtech Mar 14 '13 at 10:20
  • 7
    One can extend QML with python components. By the redundancy argument, all languages but assembler are redundant. JS and Python are distinctly not equivalent. Having serious program logic outside of QML is potentially a very good thing. – Henry Gomersall Mar 14 '13 at 10:35
  • 1
    @ddriver, as I mentioned in the question, to establish communication with OS for some specific issues we need some base language. So, I m preferring Python as Im little familiar. – inblueswithu Mar 14 '13 at 17:54

3 Answers3

31

On a conceptual level, they go together very well. I've written a python/qml/js/opengl program that combines everything fairly nicely. That was with Qt4.7 and PySide.

If you're just using QML, you can minimise the amount of Qt you'll need to be exposed to (though, as always, more knowledge makes you more powerful). Essentially, once you have a qdeclarativeview, your Qt work is done apart from the signal/slot handling, which is a joy under PySide. I would suggest that you can be productive quickly using Python and QML without worrying too much about the Qt side of things, picking it up as necessary.

From experience, I suggest making the demarcation between Python and QML clear in your own mind. I restricted the QML very much to GUI logic, which is does very well; in effect the QML handles how the interface responds to inputs, and then it sends signals back to the main program. It works a bit like creating a very basic, pared down interface between the GUI and the rest of the program, only signalling high level logic (rather than, for example, sending back a click, it would send back a signal saying for example "turn on the processing", the GUI would deal with how to render that change). In my case, this just plugged straight into my MVC framework, but you can do it how you like.

There is one big fat caveat though in all this. The development of PySide has rather stalled and currently doesn't support Qt5 and all its QML improvement goodness. There have been various discussions about how it should be supported, but not much actual code committed.

I believe PyQt supports Qt5, but dual licensed as either GPL or commercial (PySide is LGPL so can be used with closed source code). I have no experience of PyQt, other than it, and PySide being approximately drop in replacements for one-another.

It seems like I'm talking about using it as a MVVM.

(any limitations question): The whole of Qt is exposed through PySide and PyQt. This means you can write extensions in Python as you would in C. I wrote a widget that captured mouse scroll events so I could steal the scroll from a Flickable. This was a QML element created in Python, though I also had to load it from Python; I couldn't quite work out how to create an extension that I could load from inside the QML document. It's possible of course to write a C extension which is standalone to your main code, so you still always have that option.

Edit: PySide2 is now a thing and supports Qt5.

Edit2: As of 2021, Pyside is now known as QT For Python , and is very much supported up to and including QT6. Make sure you keep a note of the license.

Shayne
  • 1,571
  • 1
  • 16
  • 20
Henry Gomersall
  • 8,434
  • 3
  • 31
  • 54
  • Thank you for a clear reply. Can you please suggest me where I should use JS and Python. Should I use Python completely by almost eliminating JS for even simple functions? – inblueswithu Mar 14 '13 at 18:03
  • 5
    From professional experience, I would add that while PySide is great to work with, it has a few notable holes that can pop up and blindside you when you least expect it. The notable one that bothered me was the inability to create signals in Python that can use the normal signal hookup logic and have named parameters passed in. You have to use a hack and always connect to these signals via javascript in order to have access to the parameters in the handler function. Essentially after a couple months of development we really wished we were in C++ due to the varying issues. – Deadron Mar 14 '13 at 18:20
  • @Deadron, So. I understood from your experience that Python does not really seamlessly interact with QML. There are hurdles which may seriously effect the development. Do you accept with this? – inblueswithu Mar 14 '13 at 18:37
  • 2
    I would say that there are some hurdles, but they are not hurdles that cannot be overcome. The only few difficulties I experienced was in the passing of data between layers from QML to python. If you plan on doing complicated transitions it can be much easier working with C++. If the data passed between is kept simple or if you pass things in a serialized form it is very convenient to work with Python. tldr; If you plan on doing large complex interactions with your Qt backend you may be better off using C++ in the long run. – Deadron Mar 14 '13 at 19:11
  • 1
    I think the issue is how well the UI logic can be separated from the business logic. It's probably good discipline to make sure it is anyway. It's probably a mindset thing, if you go into it with the assumption that you're going to do UI stuff in QML/js, and only communicate with the back-end when necessary, you should be able to work well enough. – Henry Gomersall Mar 14 '13 at 19:25
  • 1
    You & @Deadron: I'll keep those things in mind. Thankyou. http://pyqt.sourceforge.net/Docs/PyQt4/qml.html This is one link I found useful. what do you say about this ? – inblueswithu Mar 15 '13 at 10:52
  • 2
    Be aware that PySide was the officially selected supported binding for Qt. I'm not sure how important this is given all that has happened but last I had checked it was preferable to use PySide over PyQt. – Deadron Mar 15 '13 at 14:04
  • 1
    @Deadron Thankyou for that. But as "Henry Gomersall" wrote _The development of PySide has rather stalled and currently doesn't support Qt5 and all its QML improvement goodness._ Even I checked its website and their pages are almost 3 years old :( – inblueswithu Mar 15 '13 at 16:34
  • 2
    Sad! Still be aware PySide is LGPL while you may need to pay for a commercial license of PyQt unless you are willing to accept one of their other licenses that require you to open source all your code. This works for personal projects but businesses can have problems with this. – Deadron Mar 15 '13 at 16:53
  • 1
    @Deadron :) Thank you both of you for sharing your opinions and experiences. – inblueswithu Mar 15 '13 at 17:46
  • @Henry , I've added a note to the bottom of your comment updating it for 2019. Feel free to rewrite it in your words. :) – Shayne Feb 02 '19 at 11:39
  • Pyside6 is *definately* not abandoned, and has been made the official python for QT and renamed "QT For Python". I guess the QT company are throwing daggers into Riverbank's PyQT. – Shayne Jun 08 '21 at 16:11
7

As of April 2016 PySide is now officially supported by the Qt Company.

The official home page is here. LGPL licensing is an option, which seems to be the main reason the project was created in the first place.

kashiraja
  • 740
  • 11
  • 24
0

1. For advanced Application and Game development Does Python & Qt-Quick do well hand in hand?

cant see why would you do game development with QT but with python this would probably be redundant overhead.
as for "advanced Application" IMO python would be a great boost because you can create dynamic stuff relatively easily, there is a caveat though, PySide is not very well integrated with qml even though there was a major proggress in PySide 6.3 it is not as polished and documented as with c++, also the python API is not very pythonic.


2. Is my Combination Trio (QML-JS-Python) is good enough for this?

For a "advanced Application" IMO no
as soon as you will squeeze the juice out of qml you will soon realize you need some custom Items and you would be needing C++ for that for two reasons:
A: Speed, python in qml property bindings are key-concept and if you have a lot of properties in python you will pay the cost. B: as i stated above the integration of python with qml is not complete. you can create afterwards your own binding for the c++ components you have created, using something like shiboken.


3. And do I need to learn Qt for App development for coupling with Python from QML? should I learn complete Qt or Only those few lines of code which stands as communication door between Python and QML?

qml and qt-widgets shares a lot in common but i think you can just start with qml and qt-core

ניר
  • 1,204
  • 1
  • 8
  • 28