PythonとQtの両方で新しくなっています。私はこのコードを試しています。 これはやや乱雑かもしれませんが、できるだけコードを削ってコアダンプを取得しようとしました。信号を送信するとコアダンプが発生します
基本的に「何か」を開始するボタンがあります。これは単なるループです。 進捗バーとラベル。
インターフェイスのボタンをクリックすると、コンソールに1が出力され、次にコアダンプが出力されます。進行状況バーまたはラベルにはデータは表示されません。
私はPython 2.7.11、Qt-4.8.7、およびPySide 1.2.2を使用しています。
スレッドコードは、このユーチューブのVIDからです: https://www.youtube.com/watch?v=ivcxZSHL7jM
は私もMainDialogクラスに、ループの外発光ラインを配置しようとしました、そしてすぐに発光信号が外部から来ているようですMainDialogクラス、それはクラッシュします。 MainDialog内でのみ動作します(テスト目的で静的整数を使用し、プログレスバーのリセット後にテストされます)。
showGui.py - ここでは何も間違っ - (デザイナーで作られpysideで換算):
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'show.ui'
#
# Created: Wed Jul 13 09:10:12 2016
# by: pyside-uic 0.2.15 running on PySide 1.2.2
#
# WARNING! All changes made in this file will be lost!
from PySide import QtCore, QtGui
class Ui_mainDialog(object):
def setupUi(self, mainDialog):
mainDialog.setObjectName("mainDialog")
mainDialog.resize(369, 171)
self.pushButton = QtGui.QPushButton(mainDialog)
self.pushButton.setGeometry(QtCore.QRect(50, 40, 84, 33))
self.pushButton.setObjectName("pushButton")
self.progressBar = QtGui.QProgressBar(mainDialog)
self.progressBar.setGeometry(QtCore.QRect(50, 110, 231, 23))
self.progressBar.setProperty("value", 0)
self.progressBar.setObjectName("progressBar")
self.label = QtGui.QLabel(mainDialog)
self.label.setGeometry(QtCore.QRect(170, 40, 81, 31))
self.label.setObjectName("label")
self.retranslateUi(mainDialog)
QtCore.QMetaObject.connectSlotsByName(mainDialog)
def retranslateUi(self, mainDialog):
mainDialog.setWindowTitle(QtGui.QApplication.translate("mainDialog", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.setText(QtGui.QApplication.translate("mainDialog", "Button", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("mainDialog", "TextLabel", None, QtGui.QApplication.UnicodeUTF8))
test.py - 信号を発するとき、これは失敗します。
from __future__ import print_function
import sys
import time
from PySide import QtCore, QtGui
import showGui
from PySide.QtCore import *
from PySide.QtGui import *
class MainDialog(QDialog, showGui.Ui_mainDialog):
def __init__(self, parent=None):
super(MainDialog, self).__init__(parent)
self.setupUi(self)
self.threadclass = ThreadClass()
self.connect(self.threadclass, QtCore.SIGNAL('GFX_PROGRESS'), self.setProgress)
self.connect(self.threadclass, QtCore.SIGNAL('TEXT_PROGRESS'), self.setTextLabel)
self.connect(self.pushButton, SIGNAL("clicked()"), self.threadclass.doSomething)
self.progressBar.reset()
def setTextLabel(self, val):
self.label.setText(val)
def setProgress(self, val):
self.progressBar.setValue(val)
class ThreadClass(QtCore.QThread):
def __init__(self, parent=None):
super(ThreadClass, self).__init__(parent)
def doSomething(self):
self.runcmd()
# some more code here
def runcmd(self):
for i in range(1, 100):
print("Status at : %s " % i)
# this one crashes
self.emit(QtCore.SIGNAL('TEXT_PROGRESS'), i)
# this one crashes too
self.emit(QtCore.SIGNAL('GFX_PROGRESS'), i)
time.sleep(1)
app = QApplication(sys.argv)
form = MainDialog()
form.show()
app.exec_()
を(https://wiki.qt.io/Signals_and_Slots_in_PySide)。エラーが発生しにくく、何か間違っていると、通常はプログラムをクラッシュさせる代わりに例外が発生します。だからあなたのクラスで 'QtCore.Signal'を定義し、' self.the_signal.emit() 'を使って' self.threadclass.the_signal.connect(self.the_slot) 'を使って接続する必要があります。 – Bakuriu