导入QquickimageProvider时PYQT5 SEG故障

发布于 2025-01-22 01:04:47 字数 1668 浏览 5 评论 0原文

我遇到了一种非常奇怪的行为,这导致了在我的应用程序上工作时遇到了SEG错误。 有人可以解释一下为什么崩溃吗?

系统:

  • Ubuntu 18.04
  • Pyqt 5.9.2
  • Python 3.6

条件:

  • 基于qapplication的类
  • Create qqmlapplicationEngine(即使未使用)
  • 导入 - 从pyqt5.qtquick import qquickimageProvider(即使未使用)
  • 具有发送/回忆的信号/插槽 (即使没有使用)列表类型并
  • 仅在实例化引擎后发送信号

那么插槽是否具有@pyqtslot decorator

**,如果我将信号签名更改为对象而不是列表,

**无关紧要** *如果您删除了一个条件之一,则您将无法获得SEG故障。

示例:

import sys

from PyQt5.QtCore import QObject, pyqtSignal
from PyQt5.QtWidgets import QApplication
from PyQt5.QtQml import QQmlApplicationEngine

from PyQt5.QtQuick import QQuickImageProvider # if you comment out it wont crash

APP = None

class SomeCrashingClass(QObject):
    sig = pyqtSignal(list)

    def __init__(self):
        QObject.__init__(self)
        self.sig.connect(self.my_func)
        self.sig.emit([None]) # if you send a [] it wont crash

    def my_func(self):
        print(f"-------------everything is fineeeeeeeeeeeeeeeeeeee-----------------")

class CrashingApp(QApplication):
    def __init__(self):
        super(CrashingApp, self).__init__(sys.argv)
        self._engine = QQmlApplicationEngine() # if you comment out it wont crash
        bla = SomeCrashingClass()

    def run(self):
        print(f"---------------------running the app ------------------")
        exit_status = self.exec_()
        print(f"----------exit status {exit_status}")


def run():
    global APP
    APP = CrashingApp()
    sys.exit(APP.run())


if __name__ == "__main__":
    run()

编辑:

  • 更改sig = pyqtsignal(object)解决问题

i've encountered a very weird behavior which led to a seg fault when working on my app.
can someone please explain why it crashes ?

system:

  • ubuntu 18.04
  • PyQt 5.9.2
  • python 3.6

conditions:

  • have a QApplication based class
  • create QQmlApplicationEngine (even if its not used)
  • import- from PyQt5.QtQuick import QQuickImageProvider (even if its not used)
  • have a signal/slot that send/recieve a list type and send a [None]
  • emit the signal only after the engine is instantiated

** it doesnt matter if the slot has a @pyqtslot decorator or not

** if i change the signal signature to object instead of list everything is fine

** if you remove even one of the conditions you wont get the seg fault.

example:

import sys

from PyQt5.QtCore import QObject, pyqtSignal
from PyQt5.QtWidgets import QApplication
from PyQt5.QtQml import QQmlApplicationEngine

from PyQt5.QtQuick import QQuickImageProvider # if you comment out it wont crash

APP = None

class SomeCrashingClass(QObject):
    sig = pyqtSignal(list)

    def __init__(self):
        QObject.__init__(self)
        self.sig.connect(self.my_func)
        self.sig.emit([None]) # if you send a [] it wont crash

    def my_func(self):
        print(f"-------------everything is fineeeeeeeeeeeeeeeeeeee-----------------")

class CrashingApp(QApplication):
    def __init__(self):
        super(CrashingApp, self).__init__(sys.argv)
        self._engine = QQmlApplicationEngine() # if you comment out it wont crash
        bla = SomeCrashingClass()

    def run(self):
        print(f"---------------------running the app ------------------")
        exit_status = self.exec_()
        print(f"----------exit status {exit_status}")


def run():
    global APP
    APP = CrashingApp()
    sys.exit(APP.run())


if __name__ == "__main__":
    run()

EDIT:

  • changing sig = pyqtSignal(object) solves the issue

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文