[Kde-perl] Re: perlQt question
Richard Dale
Richard_Dale at tipitina.demon.co.uk
Thu Aug 28 13:05:56 CEST 2003
On Thursday 28 August 2003 07:48, Richard Dale wrote:
> On Wednesday 27 August 2003 23:37, Germain Garand wrote:
> > Le Mercredi 27 Août 2003 22:28, Ashley Winters a écrit :
> > > --- Kapkaev at inbox.ru wrote:
> > > > Hi
> > > > I am not found how can I call Qt global function
> > > > 'bitBlt' from perlQt.
> > > > Can you help me?
> > > > Thanks!
> > > > (I like perlQt much more than perlTk or perlGTK...)
> > >
> > > bitBlt is being added to PerlQt now. You may need to follow special
> > > instructions to get the latest development version out of CVS, since
> > > there isn't a release version which includes it.
> >
> > Yes, I'll commit it around midnight GMT... I have to finish the
> > redirection of the new static operators and merge other changes.
> >
> > All global Qt functions are collected in a pseudo-class named
> > Qt::GlobalSpace.
> >
> > You can use them as fully qualified calls:
> > Qt::GlobalSpace::bitBlt( args...)
> > or you can export all of them (except operators, which work magically) to
> > the current namespace:
> > use Qt::GlobalSpace;
> > bitBlt(args...);
> >
> > or only a few :
> > use Qt::GlobalSpace qw( bitBlt qCompress qSysInfo );
> >
> > (that's the classical Exporter interface)
>
> The power of the new PerlQt synchronicity based bug prediction system! We
> can already be working on the problem 48 hours before a PerlQt user finds
> it.
>
> I'm having problems getting operator overloading working in QtRuby, I don't
> know how you've solved it for PerlQt. Is there a way to distinguish between
> static methods and instance methods in the SMOKE runtime? To add two
> QPoints together, you use the static method in the QGlobalSpace pseudo
> class:
>
> In QGlobalSpace:
> // +(const QCString&, const QCString&)
> const QCString xret = (*(const QCString *)x[1].s_voidp + *(const
> QCString
> *)x[2].s_voidp);
> x[0].s_voidp = (void*)new QCString(xret);
> }
>
> But to add two regions together, you use an instance method:
>
> In QRegion:
> x_14.cpp: // operator+(const QRegion&)
> x_14.cpp: const QRegion xret = this->QRegion::operator+(*(const
> QRegion *)
>
> And then there are unary static operators in QGlobalSpace:
>
> // -(const QPoint&)
> const QPoint xret = (-*(const QPoint *)x[1].s_class);
>
> So if there is some code:
>
> (a - b)
>
> Where a and b are QPoints, the QtRuby runtime first looks for a method of
> the form -a(b), which should be missing in this case, and then it should
> look for -(a, b) as a static method in QGlobalSpace.
>
> However, it finds the unary static operator in QGlobalSpace looking for
> -a(b) and assumes it's an instance method, and calls that, so it wrongly
> evaluates the expression as a, (-b)
>
> p1 = Qt::Point.new(5,5) => (5, 5)
> p2 = Qt::Point.new(20,20) => (20, 20)
> p1 - p2 => (-20, -20)
>
> findMethod() in Qt.xs doesn't distinguish between static and instance
> methods - does it need to - is that the way to solve this problem?
I got it working by looking for the +(a, b) form before +a(b).
The QRegion operator method is call 'operator+', and needs a name of
'operator+#' for findMethod() to find it. But the QPoint operator method in
QGlobalSpace is called '+' and just needs '+#' to match.
p1 = Qt::Point.new(5,5) => (5, 5)
p2 = Qt::Point.new(20,20) => (20, 20)
p1 + p2 => (25, 25)
p1 - p2 => (-15, -15)
p2 += p1 => (25, 25)
p2 -= p1 => (20, 20)
p2 * 3 => (60, 60)
# A region prints itself by displaying the result of QRegion::isNull()
r1 = Qt::Region.new() => (true)
r2 = Qt::Region.new( 100,100,200,80, Qt::Region::Ellipse ) => (false)
r1 + r2 => (false)
-- Richard
More information about the Kde-perl
mailing list