Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to use registered signal attributes from QML code #45

Closed
White-Oak opened this issue Sep 25, 2016 · 3 comments
Closed

Ability to use registered signal attributes from QML code #45

White-Oak opened this issue Sep 25, 2016 · 3 comments

Comments

@White-Oak
Copy link

White-Oak commented Sep 25, 2016

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?

@filcuc
Copy link
Owner

filcuc commented Sep 25, 2016

I would go with option 3.
Currently you can already obtain the signal argument from the qml slot.
If i'm not wrong inside a qml handler you can access the argument i-th argument with "arg0", "arg1" etc.

onNameChanged: console.log("name is", arg0)

@White-Oak
Copy link
Author

@filcuc ah, yes, so that's the fourth option to access attributes from qml handler.
Would be awesome to be able to register signals' attributes' names!

@filcuc
Copy link
Owner

filcuc commented Sep 25, 2016

@White-Oak
What's the 4th option? Just for being more clear in what i wrote in my previous message you can access the i-th argument with "arg0" because that's what the current implementation of DOtherSide does. See https://github.com/filcuc/DOtherSide/blob/master/lib/src/DosQMetaObject.cpp#L16

Obviously this is suboptimal given that we use "arg" as prefix instead of the name that the user wrote on its signal definition (however this solution simplify the development of the binding). Give me a couple of days for adding support in C++ (probably on a separate branch).

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants