在尝试运行very basic PyQt5 QML example时,我发现我遇到了分段错误。我确认它只是处理显示QML,因为an example without a window运行良好。我尝试了以下最小化测试:
#!/usr/bin/python3
import sys
from PyQt5.QtCore import QUrl
from PyQt5.QtWidgets import QGuiApplication
from PyQt5.QtQml import QQmlApplicationEngine
# Main Function
if __name__ == '__main__':
app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine("simple.qml")
engine.quit.connect(app.quit)
sys.exit(app.exec_())
simple.qml:
import QtQuick 2.5
import QtQuick.Controls 1.4
ApplicationWindow {
width: 300
height: 200
title: "Simple"
visible: true
}
当我运行这个应用程序时,会在关闭前一秒钟出现一个窗口,就像在更详细的示例中一样,我在控制台中收到Segmentation fault
(仅此而已)。
从GDB运行表明QSGRenderThread
正在接收SIGSEGV:
(gdb) run snowman_qt.py
Starting program: /usr/bin/python3 snowman_qt.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7fffe912b700 (LWP 17200)]
[New Thread 0x7fffe3dbb700 (LWP 17201)]
[New Thread 0x7fffe1442700 (LWP 17202)]
[New Thread 0x7fffdbfff700 (LWP 17203)]
Thread 5 "QSGRenderThread" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffdbfff700 (LWP 17203)]
__strstr_sse2 (haystack_start=0x0, needle_start=0x7fffe28c9dd0 "nouveau") at ../string/strstr.c:63
63 ../string/strstr.c: No such file or directory.
回溯如下:
#0 __strstr_sse2 (haystack_start=0x0, needle_start=0x7fffe28c9dd0 "nouveau") at ../string/strstr.c:63
#1 0x00007fffe27233ea in QSGRenderContext::initialize(QOpenGLContext*) ()
from /usr/local/lib/python3.5/dist-packages/PyQt5/Qt/qml/QtQuick.2/../../lib/libQt5Quick.so.5
#2 0x00007fffe273e979 in ?? ()
from /usr/local/lib/python3.5/dist-packages/PyQt5/Qt/qml/QtQuick.2/../../lib/libQt5Quick.so.5
#3 0x00007ffff56835f9 in ?? () from /usr/local/lib/python3.5/dist-packages/PyQt5/Qt/lib/libQt5Core.so.5
#4 0x00007ffff7bc16fa in start_thread (arg=0x7fffdbfff700) at pthread_create.c:333
#5 0x00007ffff78f7b5d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109
如果我运行QML文件from a C++ application,则没有分段错误且应用程序正常运行。请注意,我在没有PyOtherside的情况下使用PyQT,但症状似乎相似。
有没有办法获取更多信息以继续调试?
我在Linux Mint 18上运行Python 3.5.2。我的QT版本是5.7.0,我的PyQt版本是5.7,我的SIP版本是4.18.1。
答案 0 :(得分:1)
checkinstall
进行安装,使回滚更容易。使用最新的SIP和PyQt5,我不再收到分段错误。但是,我遇到的问题是OpenGL着色器没有正确创建,只是收到了一个纯白色的窗口。
this bug的解决方法是在Python程序中加载PyQt之前包含以下内容:
import ctypes
from ctypes import util
ctypes.CDLL(util.find_library('GL'), ctypes.RTLD_GLOBAL)
我认为这对于使用NVIDIA显卡和二进制驱动程序的基于Ubuntu的操作系统来说是独一无二的。