Skip to content

Is there a nicer syntax for getting a qt_method without using the fn syntax in there? #323

@JulianWogersien

Description

@JulianWogersien

Writing anything inside a macro is annoying because some lsp functions such as suggestions dont work
currently the best solution i have come up with is
instead of:

#[derive(QObject, Default)]
struct Greeter {
    // Specify the base class with the qt_base_class macro
    base: qt_base_class!(trait QObject),
    // Declare `name` as a property usable from Qt
    name: qt_property!(QString; NOTIFY name_changed),
    // Declare a signal
    name_changed: qt_signal!(),
    // And even a slot
    compute_greetings: qt_method!(fn compute_greetings(&self, verb: String) -> QString {
        format!("{} {}", verb, self.name.to_string()).into()
    })
}

this:

#[derive(QObject, Default)]
struct Greeter {
    // Specify the base class with the qt_base_class macro
    base: qt_base_class!(trait QObject),
    // Declare `name` as a property usable from Qt
    name: qt_property!(QString; NOTIFY name_changed),
    // Declare a signal
    name_changed: qt_signal!(),
    // And even a slot
    compute_greetings: qt_method!(fn compute_greetings(&self, verb: String) -> QString {self.r_compute_greetings(verb) })
}

impl Greeter {
  fn r_compute_greetings(&self, verb: String) -> QString {
    format!("{} {}", verb, self.name.to_string()).into()
  }
}

of course it doesnt matter that much for short functions like this, they might aswell only be done in the macro but for longer ones it gets really annoying

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions