Comments (3)
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.
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.
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)
- Rebuilding Qt bindings for upcoming Crystal 1.0 release HOT 5
- Issues with container spec HOT 1
- [Question] Dealing with classes containing template arguments
- Does not work with LLVM/Clang 14 and multi-LLVM setup
- Support for Other Languages? HOT 2
- [proposal] Update and automate documentation HOT 8
- Update or remove the Contributors section in the README HOT 1
- `find_clang` fails to find libraries HOT 1
- CrystalProc ignores Crystal-side type conversions HOT 4
- Issues wrapping namespaced classes HOT 1
- Stack overflow due to calling superclass method inside virtual override HOT 4
- Public instance properties HOT 1
- Potential premature collection of wrapped types
- Undefined reference to GC_throw_bad_alloc()
- Bindgen::Graph::Path edge cases
- Support nested anonymous types
- Destructors not called on GC-enabled instances HOT 3
- Support downcasting between Crystal wrapper types
- Some namespaced class hierarchies are not realizable
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bindgen.