私のアプリケーションをビルドする際に問題があります.pqt4とPythonでGUIを作っています.QThreadを使って2秒ごとにCPU負荷をチェックし、私は進行状況バーにそれを表示したい。私のGUIは1つのクラスにあり、私のQthreadはもう1つのクラスにあります。 PyQtはクラス、私のコードPrintScreenを、私は私の他のクラスでのQObjectにQThreadに集め、私の値を渡す方法を知りたいpyqt4とpythonを使ってあるクラスから別のクラスに値を送る方法
:
これは私のコードです。
import sys,os,module,config_read,time,threading,datecs_print,mysql.connector as mariadb,commandList
import psutil,logging
from PyQt4 import QtGui, uic ,QtSql,QtCore
from PyQt4.QtCore import QThread, SIGNAL
import resources
import webbrowser
sys.stderr = open("errlog.txt", "w")
class systemValues(QThread):
def __init__(self):
QThread.__init__(self)
def __del__(self):
self.wait()
def cpuRunValue(self):
while (1):
for x in range(2):
p = psutil.cpu_percent(1,False)
return p
def cpuProgressBarUpdate(self):
while(1):
# MyWindow.setcpuBarValue(val=77)
MyWindow.cpuBar.setValue(value=77)
def run(self):
# self.cpuRunValue()
print(self.cpuRunValue())
# self.cpuProgressBarUpdate()
class MyWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QDialog.__init__(self)
super(MyWindow, self).__init__()
file_path = os.path.abspath("ui/sales_window.ui")
uic.loadUi(file_path, self)
self.myThread = systemValues()
self.myThread.start()
def setcpuBarValue(self):
threading.Thread(target=self.cpuBar.setValue(systemValues.cpuRunValue())).start()
これは私のコードですが、エラーは発生しません。私は値を転送できません。私はcpuRunValue()からMyWindowのQprogressBarに行きます。私はこれにはあまり経験がありません。
PS:私は不要なコードをたくさん削除しましたが、詳細が必要な場合は教えてください。 ありがとうございます。
この例では、コードをテキストに含めてください。また、エラーメッセージが何であるかを伝えてください。 – titusjan
@titusjan私のコードを追加しました、それはあなたのために大丈夫ですか?何かご意見は?ありがとう、ありがとう、 –