Qt 5 development with only JavaScript
-
Hi to all,
i have been away from Qt for many many years. I know that C++ is the native solution to use it but i just wonder if that QML thing allows to use only JavaScript for Qt desktop apps development.
I mean, can i use only JavaScript for the business logic too (beside the QML UI) or C++ is the only way to code an app with Qt 5?
Thank you for every response/help!
-
Hi and welcome to devnet,
That's a bit too vague of a question. What kind of application do you have in mind ?
-
@SGaist Hi and thank you for welcoming me!
Imagine a designer that allows to assemble blocks of functionality and make connections between them and a runtime that can run the execution flow of them. I have built this a way back using C# (Windows only) and i want to explore the possibilities i have to re-write it so to be x-plat (Windows and Mac, actually). I mean, i am wondering if i can use Qt entirely from JavaScript (and QML).
Do you think something like that can be built with QML and only JavaScript?
Thank you for your help!
-
What kind of building blocks will you offer with your application ?
-
Then no, you can't do everything you are planning with only Javascript but a pretty great deal of it can be.
-
Dear @SGaist,
I am also interested in this question. Could you be more specific on what is possible and what not?
Here at CERN we have a big and long investment into Java both on the server and the client side. However, ever since Oracle has announced that they're not interested Java Client technology (and JavaFX in particular) anymore, we are looking at Qt/QML as an alternative.
We cannot re-train our Java developers to use C++ for their GUIs - it's just too complicated for them. But they could learn JavaScript. So my question is: could we base our development most of our client-side logic in JavaScript, possibly using npm packages?
Apparently one cannot just import npm modules, but has to convert them slightly to make them QML compatible, as done e.g. with https://github.com/e-fever/qmljsify.
I would very much appreciate your help...
Many thanks in advance and best regards from Geneva,
Vito
-
I don't think this question can simply be answered with yes or no.
The other question is: When it is needed to do some C++ code (either it is not possible with QML/JavaScript or it is too slow), can you do it? You still decouple GUI development and business development, so not all programmers need (deep) C++ knowledge.
If this is feasible for you, then you will get pretty far.
In any case, when starting such a big project, you should consult professional help first (either The Qt Company or one of its partners).
Regards
-
Hi,
Since your developers knows Java, they are already used to develop with a complex language so I wouldn't eliminate training them for C++ (that will likely payoff in the long run anyway).
That said, as @aha_1980 already wrote, the business logic is usually done in C++ with the GUI done with QtQuick. Depending on what your projects are, you can also leverage Qt Designer to do the GUI design with it and again, you'll only have to implement the business logic in C++.
But before making such a decision, there's a need to analyse the projects that are concerned by this migration in order to select the best tools to go forward.
-
@vbaggiol said in Qt 5 development with only JavaScript:
We cannot re-train our Java developers to use C++ for their GUIs - it's just too complicated for them.
Frankly, Java is more similar to C++ than it is to JavaScript. But you know your developers better than I do. :)
possibly using npm packages?
QML isn't exactly tied into the npm ecosystem, so that may depend on particular packages. You aren't manipulating a browser DOM with QML, so some of the expectations of a lot of the packages in NPM may make them wonky outside of a browser.
That said, JavaScript doesn't have bindings for 100% of the functionality Qt, so if you wind up needing to do something modestly esoteric, you may well wind up needing to use something other than QML with JavaScript logic. If you want something higher level than C++, I'd suggest looking at the Qt bindings for Python. They cover all of the functionality of C++, so you can more confidently make a wider range of applications than with just QML. (For example, all of QWidgets is available, you can do custom painting with QPainter, control theads, do custom OpenGL drawing, etc. )
In MVC terms, The assumption of QML is basically that you have some Model that QML is a View for, but C++ is where you make the "Controller."
-
Dear all,
Thank you for your answers, much appreciated!@wrosecrans said in Qt 5 development with only JavaScript:
@vbaggiol said in Qt 5 development with only JavaScript:
We cannot re-train our Java developers to use C++ for their GUIs - it's just too complicated for them.
Frankly, Java is more similar to C++ than it is to JavaScript. But you know your developers better than I do. :)
I've tried it with two of them, and it didn't work out. (They're experts in other domains and therefore not particularly good Java programmers either ;-)
Python, as you propose below, might indeed be a viable alternative.
I was also considering using TypeScript as a language, which IMHO is pretty close to Java. See QTBUG-68810.
Of course, we have professional C++ developers who could create specialized Qt Modules, e.g. to communicate with our servers through our CERN-specific communication middleware.
These should of course be again accessible to QML through Properties.possibly using npm packages?
QML isn't exactly tied into the npm ecosystem, so that may depend on particular packages. You aren't manipulating a browser DOM with QML, so some of the expectations of a lot of the packages in NPM may make them wonky outside of a browser.
Thanks for the clarification.
I've seen a couple of attempts to combine Qt/QML with nodejs, but they all seem to be a experimental and/or stale:
Probably nothing to pursue either :-(
Thanks again for your help!
Vito -
QML and C++ integration was there from the start and is well documented. So that wouldn't be a problem once you have your middleware written.
One thing that is worth doing before going all QML or widget is an analysis of what the your applications do and display (need of OpenGL, performance, etc.) and select the best suited technology.
As written before, designer can simplify the creation of the GUI if it makes more sense to use the QtWidgets module.