我绘制了一个简单的GUI(基本上,一个表单中的按钮 - 实际上,我注意到这是在一个更复杂的应用程序中发生的,所以我将它减少到触发问题的最小情况)使用Qt设计器并写了这个Python代码:
from PyQt4 import QtCore, QtGui, Qt
from ui_main import Ui_MainWindow
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.process = QtCore.QProcess()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
@QtCore.pyqtSignature("")
def on_pushButtonTest_clicked(self, checked=False):
QtGui.QMessageBox.information(self,'test','test')
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
mw = MainWindow()
mw.show()
sys.exit(app.exec_())
然后,当我点击pushButtonTest时,我得到一个段错误。在gdb
下运行我得到了这个回溯:
#0 0x00007ffff7ade785 in do_warn () from /usr/lib/libpython2.7.so.1.0
#1 0x00007ffff7adec4c in PyErr_WarnEx () from /usr/lib/libpython2.7.so.1.0
#2 0x00007fffe563f3b5 in ?? () from /usr/lib/python2.7/site-packages/gobject/_gobject.so
#3 0x00007fffe5b0ca00 in g_logv () from /usr/lib/libglib-2.0.so.0
#4 0x00007fffe5b0cbf2 in g_log () from /usr/lib/libglib-2.0.so.0
#5 0x00007fffe4c67a52 in ?? () from /usr/lib/libgtk-x11-2.0.so.0
#6 0x00007fffe4c69419 in ?? () from /usr/lib/libgtk-x11-2.0.so.0
#7 0x00007fffe4c69891 in ?? () from /usr/lib/libgtk-x11-2.0.so.0
#8 0x00007fffe4c6a332 in gtk_icon_theme_lookup_icon () from /usr/lib/libgtk-x11-2.0.so.0
#9 0x00007fffe4c6ae14 in gtk_icon_theme_load_icon () from /usr/lib/libgtk-x11-2.0.so.0
#10 0x00007fffe4c66311 in gtk_icon_set_render_icon () from /usr/lib/libgtk-x11-2.0.so.0
#11 0x00007fffd980e469 in ?? () from /usr/lib/libQtGui.so.4
#12 0x00007fffd980d279 in QGtkStyle::standardIconImplementation(QStyle::StandardPixmap, QStyleOption const*, QWidget const*) const () from /usr/lib/libQtGui.so.4
#13 0x00007fffd9af690f in ?? () from /usr/lib/libQtGui.so.4
#14 0x00007fffdacc15b7 in QMetaMethod::invoke(QObject*, Qt::ConnectionType, QGenericReturnArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument) const () from /usr/lib/libQtCore.so.4
#15 0x00007fffdacc398c in QMetaObject::invokeMethod(QObject*, char const*, Qt::ConnectionType, QGenericReturnArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument) () from /usr/lib/libQtCore.so.4
#16 0x00007fffd978450d in QStyle::standardIcon(QStyle::StandardPixmap, QStyleOption const*, QWidget const*) const () from /usr/lib/libQtGui.so.4
#17 0x00007fffd996575f in ?? () from /usr/lib/libQtGui.so.4
#18 0x00007fffd9965847 in QMessageBox::setIcon(QMessageBox::Icon) () from /usr/lib/libQtGui.so.4
#19 0x00007fffd9966cd3 in QMessageBox::QMessageBox(QMessageBox::Icon, QString const&, QString const&, QFlags<QMessageBox::StandardButton>, QWidget*, QFlags<Qt::WindowType>) () from /usr/lib/libQtGui.so.4
#20 0x00007fffd9966f03 in ?? () from /usr/lib/libQtGui.so.4
#21 0x00007fffd996710f in QMessageBox::information(QWidget*, QString const&, QString const&, QFlags<QMessageBox::StandardButton>, QMessageBox::StandardButton) () from /usr/lib/libQtGui.so.4
#22 0x00007fffda2dc8a6 in ?? () from /usr/lib/python2.7/site-packages/PyQt4/QtGui.so
#23 0x00007ffff7afe05a in PyEval_EvalFrameEx () from /usr/lib/libpython2.7.so.1.0
#24 0x00007ffff7afeedd in PyEval_EvalCodeEx () from /usr/lib/libpython2.7.so.1.0
#25 0x00007ffff7a8f536 in function_call () from /usr/lib/libpython2.7.so.1.0
#26 0x00007ffff7a6b8be in PyObject_Call () from /usr/lib/libpython2.7.so.1.0
#27 0x00007ffff7a79e78 in instancemethod_call () from /usr/lib/libpython2.7.so.1.0
#28 0x00007ffff7a6b8be in PyObject_Call () from /usr/lib/libpython2.7.so.1.0
#29 0x00007ffff7af8577 in PyEval_CallObjectWithKeywords () from /usr/lib/libpython2.7.so.1.0
#30 0x00007fffda9375b0 in ?? () from /usr/lib/python2.7/site-packages/sip.so
#31 0x00007fffdb208c96 in ?? () from /usr/lib/python2.7/site-packages/PyQt4/QtCore.so
#32 0x00007fffdb208fe0 in ?? () from /usr/lib/python2.7/site-packages/PyQt4/QtCore.so
#33 0x00007fffdb209061 in ?? () from /usr/lib/python2.7/site-packages/PyQt4/QtCore.so
#34 0x00007fffdacced53 in QMetaObject::activate(QObject*, QMetaObject const*, int, void**) () from /usr/lib/libQtCore.so.4
#35 0x00007fffd9af7512 in QAbstractButton::clicked(bool) () from /usr/lib/libQtGui.so.4
#36 0x00007fffd984be7e in ?? () from /usr/lib/libQtGui.so.4
#37 0x00007fffd984c6b0 in ?? () from /usr/lib/libQtGui.so.4
#38 0x00007fffd984c91c in QAbstractButton::mouseReleaseEvent(QMouseEvent*) () from /usr/lib/libQtGui.so.4
#39 0x00007fffda47161b in ?? () from /usr/lib/python2.7/site-packages/PyQt4/QtGui.so
#40 0x00007fffd94e1a49 in QWidget::event(QEvent*) () from /usr/lib/libQtGui.so.4
#41 0x00007fffda471bbb in ?? () from /usr/lib/python2.7/site-packages/PyQt4/QtGui.so
#42 0x00007fffd949218c in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib/libQtGui.so.4
#43 0x00007fffd9496e6b in QApplication::notify(QObject*, QEvent*) () from /usr/lib/libQtGui.so.4
#44 0x00007fffda48bcde in ?? () from /usr/lib/python2.7/site-packages/PyQt4/QtGui.so
#45 0x00007fffdacb96ae in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib/libQtCore.so.4
#46 0x00007fffd9492fcb in QApplicationPrivate::sendMouseEvent(QWidget*, QMouseEvent*, QWidget*, QWidget*, QWidget**, QPointer<QWidget>&, bool) () from /usr/lib/libQtGui.so.4
#47 0x00007fffd950dad4 in ?? () from /usr/lib/libQtGui.so.4
#48 0x00007fffd950c861 in QApplication::x11ProcessEvent(_XEvent*) () from /usr/lib/libQtGui.so.4
#49 0x00007fffd9532a22 in ?? () from /usr/lib/libQtGui.so.4
#50 0x00007fffe5b05845 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
#51 0x00007fffe5b05b78 in ?? () from /usr/lib/libglib-2.0.so.0
#52 0x00007fffe5b05c34 in g_main_context_iteration () from /usr/lib/libglib-2.0.so.0
#53 0x00007fffdace7b66 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/libQtCore.so.4
#54 0x00007fffd953269e in ?? () from /usr/lib/libQtGui.so.4
#55 0x00007fffdacb83ff in QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/libQtCore.so.4
#56 0x00007fffdacb8688 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/libQtCore.so.4
#57 0x00007fffdacbd328 in QCoreApplication::exec() () from /usr/lib/libQtCore.so.4
#58 0x00007fffda48a91b in ?? () from /usr/lib/python2.7/site-packages/PyQt4/QtGui.so
#59 0x00007ffff7afe05a in PyEval_EvalFrameEx () from /usr/lib/libpython2.7.so.1.0
#60 0x00007ffff7afeedd in PyEval_EvalCodeEx () from /usr/lib/libpython2.7.so.1.0
#61 0x00007ffff7afefb2 in PyEval_EvalCode () from /usr/lib/libpython2.7.so.1.0
#62 0x00007ffff7b17eea in run_mod () from /usr/lib/libpython2.7.so.1.0
#63 0x00007ffff7b18ce2 in PyRun_FileExFlags () from /usr/lib/libpython2.7.so.1.0
#64 0x00007ffff7b196fb in PyRun_SimpleFileExFlags () from /usr/lib/libpython2.7.so.1.0
#65 0x00007ffff7b2a9f2 in Py_Main () from /usr/lib/libpython2.7.so.1.0
#66 0x00007ffff7480725 in __libc_start_main () from /usr/lib/libc.so.6
#67 0x0000000000400741 in _start ()
为什么我会遇到这个段错误,我该如何解决这个问题?
我在Arch Linux上使用Qt 4.8.4和Python 2.7。
答案 0 :(得分:1)
堆栈跟踪上的那些行给了它并显示了这个段错误的(非常意外的)原因:
#8 0x00007fffe4c6a332 in gtk_icon_theme_lookup_icon () from /usr/lib/libgtk-x11-2.0.so.0
#9 0x00007fffe4c6ae14 in gtk_icon_theme_load_icon () from /usr/lib/libgtk-x11-2.0.so.0
#10 0x00007fffe4c66311 in gtk_icon_set_render_icon () from /usr/lib/libgtk-x11-2.0.so.0
#18 0x00007fffd9965847 in QMessageBox::setIcon(QMessageBox::Icon) () from /usr/lib/libQtGui.so.4
显然我的GTK图标主题被打破了;把它改成别的东西。