[Qt-interest] remove all elements from a QPainterPath

Stephen Chu stephen at ju-ju.com
Thu Mar 31 16:49:38 CEST 2011


OK. Second try. How about this?


class MyPath : public QPainterPath {
public:
  MyPath() : a(1234), painterPath(this) {}
  void clear() {
    *painterPath = QPainterPath();
  }
private:
  int a;
  QPainterPath * painterPath;
};

It probably breaks more rules than the lines in it. But it seems to work 
in my setup.


In article 
<stephen-F1C50B.10423431032011 at r186-50-238-87.dialup.adsl.anteldata.net.
uy>,
 Stephen Chu <stephen at ju-ju.com> wrote:

> You are right. It doesn't really work since it will also leave other 
> data members in MyPath in some undefined state.
> 
> Well. I tried. :)
> 
> In article 
> <AANLkTikQbSUdt=x6oWCuDgCLswehMRt3VGF_5xBX3dMG at mail.gmail.com>,
>  Sean Hayes <sean.t.hayes at vanderbilt.edu> wrote:
> 
> > Markus,
> > 
> > Very clever thought. However, I believe that making assignments to the this
> > pointer violates the C++ standards and will not compile on most modern
> > compilers. Therefore, the following statement should not work.
> > 
> > *this = QPainterPath();
> > 
> > I have heard that you can get this functionality in gcc by using
> > "-fthis-is-variable". However, that would be really bad practice for new
> > code. Even if it did compile, wouldn't it only change the value of the local
> > copy of the this pointer? That is, the new value of this would leave scope
> > when the method returned.
> > 
> > Regards,
> > Sean
> > 
> > On Thu, Mar 31, 2011 at 8:51 AM, Stephen Chu <stephen at ju-ju.com> wrote:
> > 
> > > In article
> > > <OF3CD162E1.6EF3F42A-ONC1257864.0026ABC7-C1257864.00291B34 at sebakmt.com>,
> > >  Markus Franke <Franke.M at sebakmt.com> wrote:
> > >
> > > > Dear Alex,
> > > >
> > > > thanks for your reply. However, this is not really what I want to
> > > achieve.
> > > >
> > > > I would like to inherit from QPainterPath and then clear the path from
> > > > within a member function of this derived class.
> > > >
> > > > Best regards,
> > > > Markus Franke
> > >
> > > How about this?
> > >
> > > class MyPath : public QPainterPath {
> > >   MyPath(const QPainterPath & copy) : QPainterPath(copy) {}
> > >   void clear() {
> > >      *this = QPainterPath();
> > >   }
> > > };
> > >
> > > --
> > > Stephen Chu
> > > _______________________________________________
> > > Qt-interest mailing list
> > > Qt-interest at qt.nokia.com
> > > http://lists.qt.nokia.com/mailman/listinfo/qt-interest
> > >

-- 
Stephen Chu



More information about the Qt-interest-old mailing list