Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. CoffeeScript in qml, proof of concept.
Forum Updated to NodeBB v4.3 + New Features

CoffeeScript in qml, proof of concept.

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 3 Posters 2.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Corngood
    wrote on 2 Jul 2013, 01:43 last edited by
    #1

    In case anyone's interested, I hacked together a fork of qtdeclarative (based on dev) that allows coffeescript to be used in QML:

    https://github.com/corngood/qtdeclarative.git

    I've just been using it in a small hobby project, so I'm not making any promises about how well it works.

    You can make a standalone script file with a .coffee extension, and add:

    @.pragma language "coffeescript"@

    Then use:

    @import "test.coffee" as Test@

    In qml, for property assignments and signal handlers, instead of using a colon, you can put a ->

    @
    Loader {
    source -> if someFlag then "a.qml" else "b.qml"
    Keys.onPressed ->
    if event.key is Qt.Key_F1
    doSomething()
    event.accepted = true
    }
    @

    Everything after the -> will be parsed as a block of coffeescript until it finds a line that is equally or less indented than the line on which -> occurred. That's kind of dirty, but since coffeescript cares about indentation it doesn't bother me too much. Standard qml syntax will still be interpreted as javascript, and it's probably best to use it for ids/literals.

    Something to be aware of is that coffeescript will not let you assign a qml global (e.g. property on current object) with "property = value", and will instead declare a local 'var property'. To work around this you'll need to assign an id to the object and use "id.property = value".

    Things I've been thinking about for future work:

    1. hooks for qml/js translation in qtdeclarative, and coffeescript support in a plugin
    2. writing of translated qml/js (e.g. for build time translation)
    3. a pure coffeescript dialect of qml, using coffeescript's object notation
    4. modified coffeescript compiler that understands qml globals
    5. sourcemap support for debugging
    1 Reply Last reply
    0
    • T Offline
      T Offline
      trusktr
      wrote on 12 Oct 2013, 07:53 last edited by
      #2

      nice.

      1 Reply Last reply
      0
      • H Offline
        H Offline
        Helbrass
        wrote on 12 Oct 2013, 13:45 last edited by
        #3

        Hm, that's an interesting development! Not that it makes much difference to me personally, I would really like to see proper language, like Python, instead of JS :)

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved