ryanmelt / qtbindings

An easy to install gem version of the Ruby bindings to Qt
http://github.com/ryanmelt/qtbindings
Other
340 stars 63 forks source link

Qt::Polygon and Qt::PolygonF enumerable methods #129

Closed csdehaan closed 7 years ago

csdehaan commented 8 years ago

When using any of the Enumerable methods (count, each, etc) of the polygon classes I get a SystemStackError. It appears that the problem is in the each method that is defined in lib/Qt/qtruby4.rb (line 1672 for Polygon and 1683 for PolygonF). The each method uses count to figure out how many points are in the polygon, but this can't work because the count method (from Enumerable) uses each to count the number of items in the Enumerable object. This causes an infinite recursion and therefore the stack error. It seems like the way to fix it would be to expose the count() function of the QPolygon(F) classes and use that instead of the Enumerable version of count. Unfortunately I do not know how to do this, can someone point me in the right direction? Also, here is a simple example that shows the problem:

require 'Qt4'

poly = Qt::Polygon.new([Qt::Point.new(1,2),Qt::Point.new(3,4),Qt::Point.new(1,2)])

poly.each do |pt|
  puts pt
end
csdehaan commented 8 years ago

I think I found what I was looking for in ext/ruby/qtruby/src/qtruby.cpp. I followed the example of qitemselection_count() and qitemselection_at() to expose the polygon count and at functions and then mapped those into the Qt::Polygon(F) classes. Opened a pull request to include those changes.

ghost commented 7 years ago

closed by #130