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

Support lifetime parameters on the Q_OBJECT macro #7

Open
paulolieuthier opened this issue Apr 2, 2015 · 1 comment
Open

Support lifetime parameters on the Q_OBJECT macro #7

paulolieuthier opened this issue Apr 2, 2015 · 1 comment

Comments

@paulolieuthier
Copy link

Problem:

struct PG
{
    engine: &mut Engine, -- lifetime error here
    names: Vec<String>
}

Q_OBJECT! { PG:
    slot fn parse(String);
}

To fix the code, I use a lifetime parameter for PG:

struct PG<'a>
{
    engine: &'a mut Engine, // works :)
    names: Vec<String>
}

Q_OBJECT! { PG<'a>: // but now this is broken :(
    slot fn parse(String);
}

This is what the compiler says:

src/main.rs:52:16: 52:18 error: use of undeclared lifetime name `'a` [E0261]
src/main.rs:52 Q_OBJECT! { PG<'a>:
                              ^~

And if I don't use the lifetime parameter in the macro:

src/main.rs:52:13: 52:15 error: wrong number of lifetime parameters: expected 1, found 0 [E0107]
src/main.rs:52 Q_OBJECT! { PG:
                           ^~

Apparently, the macro understands the type just fine, but can't find the definition of 'a. It should be as in impl, where the parameter is defined before used:

impl<'a> PG<'a>

I'm trying to find how to fix this, or how to improve Q_OBJECT, but no success so far.

@florianjacob
Copy link
Collaborator

It's currently not possible to capture a lifetime parameter with a macro, but there's a rust issue for that.

I think the best current solution to this would be to have smaller macros which would help to implement something like this by hand:

impl<'a> qmlrs::Object for PG<'a> {
    fn qt_metaobject() => qmlrs::MetaObject {}
    fn qt_metacall() {}
}

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