python中KIO的分段错误?

时间:2011-06-13 08:48:34

标签: python qt segmentation-fault kde

以下小型python程序使用KDE API来检索URL的内容。不幸的是,它是段错误。我做错了什么,或者这是KDE中的错误?

kio.py:

#!/usr/bin/env python2
# coding: utf-8

from PyKDE4 import kdecore,kio
url = kdecore.KUrl("http://www.google.com")
print url
kio.KIO.get(url)
print "ok!"

运行它:

[joel@mouton tmp]$ ./kio.py 
PyQt4.QtCore.QUrl(u'http://www.google.com')
Segmentation fault (core dumped)

回溯:

(gdb) bt
#0  0xb6a352a4 in QObject::thread() const () from /usr/lib/libQtCore.so.4
#1  0xb46f0b43 in ?? () from /usr/lib/libkio.so.5
#2  0xb46f0eaa in KIO::Scheduler::doJob(KIO::SimpleJob*) () from /usr/lib/libkio.so.5
#3  0xb464bb8c in ?? () from /usr/lib/libkio.so.5
#4  0xb464d81a in KIO::TransferJob::TransferJob(KIO::TransferJobPrivate&) () from /usr/lib/libkio.so.5
#5  0xb4652c69 in KIO::get(KUrl const&, KIO::LoadType, QFlags<KIO::JobFlag>) () from /usr/lib/libkio.so.5
#6  0xb4b0649b in ?? () from /usr/lib/python2.7/site-packages/PyKDE4/kio.so
#7  0xb762425a in PyCFunction_Call () from /usr/lib/libpython2.7.so.1.0
#8  0xb7682182 in PyEval_EvalFrameEx () from /usr/lib/libpython2.7.so.1.0
#9  0xb7683f70 in PyEval_EvalCodeEx () from /usr/lib/libpython2.7.so.1.0
#10 0xb76840c3 in PyEval_EvalCode () from /usr/lib/libpython2.7.so.1.0
#11 0xb769dc0b in run_mod () from /usr/lib/libpython2.7.so.1.0
#12 0xb769eaf2 in PyRun_FileExFlags () from /usr/lib/libpython2.7.so.1.0
#13 0xb769f7cc in PyRun_SimpleFileExFlags () from /usr/lib/libpython2.7.so.1.0
#14 0xb76a0372 in PyRun_AnyFileExFlags () from /usr/lib/libpython2.7.so.1.0
#15 0xb76b18fc in Py_Main () from /usr/lib/libpython2.7.so.1.0
#16 0x08048557 in main ()

如果重要的话,我在Arch Linux上使用最新的python 2.7。

1 个答案:

答案 0 :(得分:1)

您需要运行一个事件循环才能使其正常工作,这意味着Q或KApplication取决于您正在使用的内容。我通常使用KApplication。

KDE示例模块中提供了有关KIO使用PyKDE4的更多信息:

https://projects.kde.org/projects/kde/kdeexamples/repository/revisions/master/show/bindings/python/kio