Giter Site home page Giter Site logo

Overloaded Qt signals about bindgen HOT 3 CLOSED

papierkorb avatar papierkorb commented on June 18, 2024
Overloaded Qt signals

from bindgen.

Comments (3)

HertzDevil avatar HertzDevil commented on June 18, 2024 2

I took a look at PyQt5. It exposes signals and slots directly, and quite conveniently gives the following example for QComboBox:

from PyQt5.QtWidgets import QComboBox

class Bar(QComboBox):

    def connect_activated(self):
        # The PyQt5 documentation will define what the default overload is.
        # In this case it is the overload with the single integer argument.
        self.activated.connect(self.handle_int)

        # For non-default overloads we have to specify which we want to
        # connect.  In this case the one with the single string argument.
        # (Note that we could also explicitly specify the default if we
        # wanted to.)
        self.activated[str].connect(self.handle_string)

    def handle_int(self, index):
        print "activated signal passed integer", index

    def handle_string(self, text):
        print "activated signal passed QString", text

In Python str is a class, and a particular overload is selected by the classes that go between the []. I think we could imitate this by requiring classes themselves as arguments to #on_SIGNAL:

module Qt
  class ComboBox
    def on_activated(_type1_ : Int32.class, &_proc_ : Proc(Int32, Void)) : SignalConnection    
    def on_activated(_type1_ : String.class, &_proc_ : Proc(String, Void)) : SignalConnection
  end
end

cb = Qt::ComboBox.new
cb.on_activated(Int32) { |x| puts "item index #{x}" }
cb.on_activated(String) { |x| puts "item text #{x}" }

The Qt processor would need to detect all such overloads and inject those dummy type arguments only for signals that are overloaded; signals with unique signatures could stay the same. Classes are constant values in Crystal, so this approach should have little to no overhead while remaining readable. The only possible ambiguity is when one of the overloads takes no arguments, as the generated method would then look like one without overloads (it probably doesn't matter).

I don't know how the PyQt5 documentation defines what the default overload is. I don't think we need that either.

from bindgen.

docelic avatar docelic commented on June 18, 2024

Hey @HertzDevil that's an interesting question.
@Papierkorb do you have a preference on how you'd like to see this issue solved/worked around?

from bindgen.

Papierkorb avatar Papierkorb commented on June 18, 2024

I think passing the type as argument for overloaded signals is a clever solution! I don't think there needs to be a "default" signal, as we can't predict the most useful overload so let's not.

For an overload where one signal comes with no arguments the resulting on_method could simply take no arguments beyond the block.

from bindgen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.