简单的PyQt5 QML应用程序导致分割fau

2024-04-20 08:14:07 发布

您现在位置:Python中文网/ 问答频道 /正文

在尝试运行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_())

在简单.qml公司名称:

^{pr2}$

当我运行这个应用程序时,一个窗口在关闭之前会出现一瞬间,就像在更详细的示例中一样,我在控制台中接收到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,则没有分段错误,应用程序可以工作。请注意,我使用的PyQT不含PyOtherside,但症状似乎相似。在

有没有办法获取更多信息以继续调试?在

我在LinuxMint18上运行Python3.5.2。我的QT版本是5.7.0,PyQt版本是5.7,SIP版本是4.18.1。在


Tags: infromimportnewlibusrsysqml
1条回答
网友
1楼 · 发布于 2024-04-20 08:14:07

兔子洞比我想象的要深。有一些问题。在

  1. Linux Mint 18(可能是Ubuntu16.04)存储库中的SIP版本太旧了。我通过installing from source更新到4.18.1。在
  2. 有了更新的SIP版本,我能够compile the latest PyQt5 from source。然而,在编译之前,我必须安装libqt5opengl5 dev,以便它可以使用QtOpenGL模块进行编译。在编译之后,我使用checkinstall进行了安装,以使回滚更容易。在

使用最新的SIP和PyQt5,我不再收到分段错误。但是,我遇到了OpenGL着色器没有正确创建的问题,只是收到了一个纯白色的窗口。在

this bug的解决方法是在将PyQt加载到Python程序之前包括以下内容:

import ctypes
from ctypes import util
ctypes.CDLL(util.find_library('GL'), ctypes.RTLD_GLOBAL)

我相信这是独一无二的基于Ubuntu的操作系统,带有NVIDIA显卡和二进制驱动程序。在

相关问题 更多 >