Skip to content

Ability to use registered signal attributes from QML code #45

@White-Oak

Description

@White-Oak

The original issue is White-Oak/qml-rust#8.

So the problem is :

  • onPageDownloaded is a signal fn pageDownloaded(response: String)
  • onPageDownloaded: console.log("Page Downloaded "+ response); fails with an error ReferenceError: response is not defined, because attributes' names are not used on registration.

I see three solutions to the original problem:

  1. Use arguments:
onPageDownloaded: console.log("Page downloaded " + arguments[0]);

Remember, that in JS you can always check what are the arguments of the function (see this answer on SO)
2. Connect signal to function in qml like this

  Component.onCompleted: {
    visible = true;
    logic.pageDownloaded.connect(jsPageDownloaded);
  }

  function jsPageDownloaded(response) {
    console.log("Page downloaded " + response);
  }
  // ...

This is more verbose.
3. Provide an ability to register attribute name on registration.
Currently SignalDefinition consists of signal's name, number of attributes and their types. Is it possible to provide names of attributes as well?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions