Is it possible to use JavaScript for programming in Qt? If so, is it less safe?

  • Dear people out there,

    May I ask you something? I am a Windows programmer, but I'm sincerely interested into dropping off down the road of Linux programming. I mean, desktop applications.

    I could learn C++ to use Qt natively, or, I could use JavaScript I learnt from webdevelopment. But would such thing be possible? Of course there are tons of plugins and extensions out there on internet. But, is it officially supported? Is it something that is allowed to enter Qt? Or are they some kind of hacks?

    The other question, whether JavaScript would be supported, are they less safe than C++ applications both made by Qt? I know that safety of program depends on programming, but even when program is written well, it would be easier to find bug in DOS or PHP, than compiled Assembly, and it's not even about how defended code is, but it's just made to be protected.

    Would making application in JavaScript, make program somehow more vulnerable than C++ program would make it? I mean, JavaScript is extremely dependent to an amount of libraries, can Qt deal with this and somehow back-up JavaScript in it? C++ on the other hand is only vulnerable if you know the compiler, nothing else can be really done to it. While JavaScript's compiler and interpreter can be hijacked. (that's why I don't like Java, many bugs)

    Sincerely, Adrian M.

  • HI and welcome to devnet,

    Qt is a C++ toolkit so the official languange is the C++.
    Using the new technology (QtQuick) you can write the UI using the declarative language QML and some Javascript code; the business logic must be implemented in C++ (for non trivial application).

    There's no way (thanks God) to use external Javascript libraries

  • As @mcosta said, you could use JavaScript if you develop applications using QML and Qt Quick.

    Please, read more here.

  • I am not sure why you would want that, but in any case @mcosta is correct. Have a look to some QML examples that use javascript here and here.

    If those examples are close to what you have in mind then a good place to start would be from here

    Moreover there is the option of using QtScript that can support scripts written in ECMAScript. A language somewhat similar to javascript. Have a look here.

    As for your security concerns I would say that it is hard to answer. You can add you qml code inside your project resources obfuscating it for example, but in general this is not a meaningful question. It depends on what you are making and how you define secure.

  • You might aswell want to check out the QtQuickCompiler which allows you to compile your .qml files (containing the QML and JavaScript) which improving the startup-time. Also you won't need to deploy the .qml files with your applications, which might increase the security. :)

  • Thank you for reply everybody.

    Apparently, I'd need to learn C++, but no problem, there's tons of resources out there.