[PyKDE] "import khtml" causes weird problem

Jim Bublitz jbublitz at nwinternet.com
Thu Feb 9 08:39:49 GMT 2006


On Wednesday 08 February 2006 17:44, D Bera wrote:
> Hi
> Have a look at this simple script below trying out kio.filepreview.
>
> If I dont include "import khtml" at (1), slot_preview prints
> <class 'kio.KFileItem'>
> <kio.KFileItem object at 0xb74d3d2c>
>
> If I include "import khtml" at (1), slot_preview prints
> <type 'NotImplementedType'>
> NotImplemented
>
> (I found this in another app which uses khtml, so I really need that
> "import khtml" thing there. The problem exists even if I explicitly say
> "from khtml import ...").
> --------------------------------------
> #!/usr/bin/env python
>
> import sys
> from qt import *
> from kdecore import *
> from kio import *
> from kdeui import *
> import khtml    <----------------- (1)
>
> def clicked ():
>     urllist = QStringList ()
>     urllist.append ("/home/debajyoti/LookNFeel/alien-night.jpg")
>     job = KIO.filePreview (KURL.List (urllist), 128, 0, 0, 70, False,
> False) a.connect (job, SIGNAL ("gotPreview (const KFileItem *, const
> QPixmap &)"), slot_preview)
>     a.connect (job, SIGNAL ("failed (const KFileItem *)"), slot_preview)
>
> def slot_preview (kfileitem, preview=None):
>     print type (kfileitem)
>     print kfileitem
>
> a = KApplication (sys.argv, "hello")
> w = QWidget ()
> button = QPushButton (w)
> a.connect (button, SIGNAL ("clicked ()"), clicked)
>
> a.setMainWidget(w)
> a.setTopWidget(w)
> w.resize(200,100)
> w.move (100, 100)
> w.show()
> a.exec_loop()
> --------------------------------------------
>
> versions:
> Qt: 3.3.4
> KDE: 3.4.2
> sip: 4.3.2
> pyqt: 3.15.1
> pykde: latest snapshot snapshot20060122
> python: 2.4.1
> anything else ?
>
> If I move the import statement to after "a.connect (...)" then the first
> time, kfileitem gets the proper type, and becomes notimplemented
> henceforth. It happened with an earlier version of sip,pyqt and pykde - so
> this is something not suddenly new.
> I dont have enough knowledge of sip et al, but looks like there is some
> problem with the module name getting stolen or lost when khtml is imported
> (!!!).
> Is there any way, I can go around this problem ?

The basic problem seems to be that if khtml or kparts are imported, the type 
of the first argument passed to the slot by gotPreview is destroyed or the 
entire object is being damaged somehow.

We discussed this offlist today, and I couldn't replicate the error with 
PyKDE/PyQt built with sip 4.1.1.  However I got about the same thing tonight 
with the sip 20060111 snapshot, and the poster was using sip 4.2 originally, 
so it seems to be a problem only with more recent sip versions.

Making 'job' global (since it goes out of scope) makes no difference, and 
neither does explicitly importing classes instead of using *. It also fails 
if kparts is imported, and the problem might be with kparts, since khtml 
depends on it. KIO.filePreview, KFileItem and KIO.PreviewJob (which is the 
type of 'job') come from the kio module, on which kparts and khtml both 
depend. kabc, kresources, kfile and kutils also depend on kio and they work 
fine. I couldn't find any apparent difference in C++ code between modules 
that work and those that don't - they all reference the relevant kio classes 
in exactly the same way, and none of those classes seemed to be used in code 
in kparts or khtml. There don't seem to be any name clashes with any of the 
classes or methods involved.

While the poster gets a "NotImplemented" error, in the slot I got a type of 
'list' for kfileitem (should be type KFileItem), and the value of the list 
was:

[<KFileiItem object>, <nil>, <nil>, <nil>, ...] 

I presume until all available memory is consumed, since it worked through half 
the swap file before I killed it.

There are two signals connected to the slot, but it's the 'gotPreview' signal 
that's emitted (assuming a valid file name is used - I split the single slot 
into one slot for each signal).

It could be a problem with KURL::List - there are two 'filePreview' functions:

namespace KIO
{
   KIO::PreviewJob* filePreview (KURL::List, ...)
   KIO::PreviewJob* filePreview (KFileList, ...)
}

where KFileList is a mapped type of QPtrList<KFileItem>. I haven't looked at 
that (the second function) yet, beyond one attempt where I ran into a problem 
in the KFileItem ctor where the C++ code is trying to figure out the mime 
type of the file and I ran into a segfault somewhere in the Qt unicode 
processing code. The second function is basically just a call to the 
KIO::PreviewJob ctor; the first function converts the KURL::List to a 
KFileList and the calls the KIO::PreviewJob ctor.

Jim




More information about the PyQt mailing list