[PyKDE] C++ Anomalie

Jim Bublitz jbublitz at nwinternet.com
Thu Oct 5 08:55:46 BST 2006


I realize this isn't a PyKDE question, but there are some good C++ programmers 
here, and I thought maybe someone could tell me what's going on here. I've 
had this problem with the SuSE rpms of KSpread, and even recompiled KSpread 
with debug info and get the same result.

I'm duplicating some KSpread code in trying to do Python scripting with 
KSpread. The code I'm copying is directly from KSpread and seems to work 
there (it's invoked any time you format a cell). One statement in the code 
I've copied leads to a situation where the following methods eventually get 
called.

Notice that the variable 'range' is declared as an argument of type QRect&. 
Nowhere in the following method does QString appear, yet the createRange call 
at the end of the first method invariably calls the QString version of 
createRange, which then segfaults (because it's calling QString methods on 
what's really a QRect).

Anybody have any idea what's going on?

Jim

Region::Iterator Region::insert(Region::Iterator pos, const QRect& range, 
Sheet* sheet, bool multi)
{

   ...

  if ( !containsRange )
  {
    printf ("is range a QRect?\n");
    printf ("range x = %i y = %i\n", range.x (), range.y ());
    printf ("calling createRange\n");
    Range* rrange = createRange(range);

 ...
}


Region::Range* Region::createRange(const QRect& rect) const
{
  printf ("create range from rect\n");
  return new Range(rect);
}

// this always gets called, even though 'range' is a QRect.

Region::Range* Region::createRange(const QString& string) const
{
  printf ("create range from string\n");
  return new Range(string);
}


Program Output:

is range a QRect?
range x = 1 y = 1
calling createRange
create range from string
KCrash: Application 'testKSpread.py' crashing...


Traceback:

[KCrash handler]
#9  0x40ef5770 in QString::find () from /usr/lib/libqt-mt.so.3
#10 0x42f03cad in QString::find (this=0xbfd4e3c0, c=58 ':', index=0, cs=false)
    at qstring.h:996
#11 0x4305a218 in Range (this=0x8490078, sRange=@0xbfd4e3c0) at region.cc:913
#12 0x4305a349 in KSpread::Region::createRange (this=0x83a2eb8, 
    string=@0xbfd4e3c0) at region.cc:732
    =====

Note the type of the arg in #12 above.




More information about the PyQt mailing list