Bug 385341 - Support member functions in the interface
Summary: Support member functions in the interface
Status: RESOLVED FIXED
Alias: None
Product: rust-qt-binding-generator
Classification: Unmaintained
Component: general (show other bugs)
Version: unspecified
Platform: Other All
: NOR wishlist
Target Milestone: ---
Assignee: Jos van den Oever
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-10-03 20:21 UTC by Jos van den Oever
Modified: 2017-11-01 12:19 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jos van den Oever 2017-10-03 20:21:56 UTC
Currently the generator supports writing data models that are synced between rust and Qt. There is a wish for generating bindings for functions.

A possible syntax could be this:

"MyObject": {
    "type": "Object",
    "functions": {
        "removeDoneItems": {
            "arguments": [],
            "return": "void"
        },
        "removeLargeItems": {
            "arguments": [{
                "name": "thresholdSize",
                "type": "quint32"
            }],
            "return": "void"
        }
    }
}
Comment 1 Pearce Keesling 2017-10-11 19:49:23 UTC
I've got most of the this solved. The only thing that's left as far as I can tell is the interface going back from rust String to a QString. I'll need to take a look at that when I get the time. I was able to make use of this in the qml_todo example I wrote. The only problem I'm having with that is that I can't find any way to batch together all of the removals. QT seems to require that you do a begin_removal before each set of consecutive removals. There doesn't seem to be a way to start a removal then remove items 1, 3, 5 or something like that.
Comment 2 Pearce Keesling 2017-10-11 19:51:37 UTC
Something else I was wondering. Is there a particular reason that we're requiring argument names? As far as I can tell there is never really a place that those are needed from a developer's perspective. The Rust-C interface doesn't care about argument names so we could just call it arg1, arg2, etc. as long as we get the types and order correct.
Comment 3 Jos van den Oever 2017-10-12 15:10:17 UTC
There is code to convert std::string::String to QString and back. This always requires a memory allocation because the encoding has to change between utf8 and utf16.

"QT seems to require that you do a begin_removal before each set of consecutive removals." Yes, that is true.

"Is there a particular reason that we're requiring argument names?" It is helpful when reading the code. Generated code will still show up in your IDE and arg1, arg2 etc are not nice there.