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. QML JS function return type `void`
Forum Updated to NodeBB v4.3 + New Features

QML JS function return type `void`

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 2 Posters 1.9k Views
  • 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.
  • P Offline
    P Offline
    paulmasri
    wrote on 10 Nov 2022, 10:45 last edited by
    #1

    Yesterday at QtWS22, Ulf Hermann gave a talk about using strongly typed JavaScript, so that QML JS code can be compiled to C++.

    This included providing the function return type.
    e.g.

    function myQmlFunction(msg: string) : string {
      console.log("Got message:", msg)
      return "some return value"
     }
    

    I took this example from this documentation page about QML-C++ integration.

    The page says:

    You can use value types and object types as type names

    However I've tried using return type void (which is one of the listed value types) but this generates a syntax error.

    What should we do, for our function to be a good candidate for compilation to C++, if a function does not return anything?

    J 1 Reply Last reply 10 Nov 2022, 10:57
    0
    • P paulmasri
      10 Nov 2022, 10:45

      Yesterday at QtWS22, Ulf Hermann gave a talk about using strongly typed JavaScript, so that QML JS code can be compiled to C++.

      This included providing the function return type.
      e.g.

      function myQmlFunction(msg: string) : string {
        console.log("Got message:", msg)
        return "some return value"
       }
      

      I took this example from this documentation page about QML-C++ integration.

      The page says:

      You can use value types and object types as type names

      However I've tried using return type void (which is one of the listed value types) but this generates a syntax error.

      What should we do, for our function to be a good candidate for compilation to C++, if a function does not return anything?

      J Offline
      J Offline
      JonB
      wrote on 10 Nov 2022, 10:57 last edited by
      #2

      @paulmasri
      I know nothing about QML, but you are saying the example at https://doc.qt.io/qt-6/qml-void.html generates a syntax error?

      1 Reply Last reply
      0
      • P Offline
        P Offline
        paulmasri
        wrote on 10 Nov 2022, 11:16 last edited by paulmasri 11 Oct 2022, 11:16
        #3

        @JonB I hadn't tried that documentation page. Good to see an example.

        @JonB said in QML JS function return type void:

        I know nothing about QML, but you are saying the example at https://doc.qt.io/qt-6/qml-void.html generates a syntax error?

        Yes I am.

        Screenshot 2022-11-10 at 11.12.46.png

        FYI I'm using Qt 6.3, which does support other types, such as string, int, etc.

        Sounds like a bug.

        J 1 Reply Last reply 10 Nov 2022, 12:54
        0
        • P Offline
          P Offline
          paulmasri
          wrote on 10 Nov 2022, 11:24 last edited by
          #4

          Well, actually looking again at the documentation, Qt 6.2 LTS lists the QML Basic Types but it doesn't include void as one of these; whereas Qt 6.4 replaces QML Basic Types with QML Value Types and does include void.

          So it looks like there was a step change for Qt 6.4. (Wish the documentation would say it was introduced in Qt 6.4!)

          So the weirdness is that in Qt 6.3 void is not supported as a value type but string and int are, if it's true that value types don't exist at all before Qt 6.4

          1 Reply Last reply
          0
          • P paulmasri
            10 Nov 2022, 11:16

            @JonB I hadn't tried that documentation page. Good to see an example.

            @JonB said in QML JS function return type void:

            I know nothing about QML, but you are saying the example at https://doc.qt.io/qt-6/qml-void.html generates a syntax error?

            Yes I am.

            Screenshot 2022-11-10 at 11.12.46.png

            FYI I'm using Qt 6.3, which does support other types, such as string, int, etc.

            Sounds like a bug.

            J Offline
            J Offline
            JonB
            wrote on 10 Nov 2022, 12:54 last edited by
            #5

            @paulmasri
            One thing: that looks like a warning in the code editor parser. Does it cause any problem/generate an error when you run the code?

            P 1 Reply Last reply 11 Nov 2022, 15:44
            1
            • J JonB
              10 Nov 2022, 12:54

              @paulmasri
              One thing: that looks like a warning in the code editor parser. Does it cause any problem/generate an error when you run the code?

              P Offline
              P Offline
              paulmasri
              wrote on 11 Nov 2022, 15:44 last edited by
              #6

              @JonB said in QML JS function return type `void`:

              @paulmasri
              One thing: that looks like a warning in the code editor parser. Does it cause any problem/generate an error when you run the code?

              Warnings are yellow, errors red in my setup. Yes it does cause build errors, not just Qt Creator syntax errors. (Good question though as sometimes qmllint is not correct in Qt Creator.)

              1 Reply Last reply
              0

              1/6

              10 Nov 2022, 10:45

              • Login

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