久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <tfoot id='idKGB'></tfoot>
  • <legend id='idKGB'><style id='idKGB'><dir id='idKGB'><q id='idKGB'></q></dir></style></legend>

      <small id='idKGB'></small><noframes id='idKGB'>

      <i id='idKGB'><tr id='idKGB'><dt id='idKGB'><q id='idKGB'><span id='idKGB'><b id='idKGB'><form id='idKGB'><ins id='idKGB'></ins><ul id='idKGB'></ul><sub id='idKGB'></sub></form><legend id='idKGB'></legend><bdo id='idKGB'><pre id='idKGB'><center id='idKGB'></center></pre></bdo></b><th id='idKGB'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='idKGB'><tfoot id='idKGB'></tfoot><dl id='idKGB'><fieldset id='idKGB'></fieldset></dl></div>

        • <bdo id='idKGB'></bdo><ul id='idKGB'></ul>

        PyQt5“定時器不能從另一個線程啟動"更改 Q

        PyQt5 quot;Timers cannot be started from another threadquot; error when changing size of QLabel(PyQt5“定時器不能從另一個線程啟動更改 QLabel 的大小時出錯)
            <legend id='pthT1'><style id='pthT1'><dir id='pthT1'><q id='pthT1'></q></dir></style></legend>
            <tfoot id='pthT1'></tfoot>
              <tbody id='pthT1'></tbody>
          • <small id='pthT1'></small><noframes id='pthT1'>

                <bdo id='pthT1'></bdo><ul id='pthT1'></ul>

                  <i id='pthT1'><tr id='pthT1'><dt id='pthT1'><q id='pthT1'><span id='pthT1'><b id='pthT1'><form id='pthT1'><ins id='pthT1'></ins><ul id='pthT1'></ul><sub id='pthT1'></sub></form><legend id='pthT1'></legend><bdo id='pthT1'><pre id='pthT1'><center id='pthT1'></center></pre></bdo></b><th id='pthT1'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='pthT1'><tfoot id='pthT1'></tfoot><dl id='pthT1'><fieldset id='pthT1'></fieldset></dl></div>

                1. 本文介紹了PyQt5“定時器不能從另一個線程啟動"更改 QLabel 的大小時出錯的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我在 Python 3.5 中遇到了一個奇怪的 PyQt5 問題.我有兩個類,FrontEnd(QWidget)TimerThread(Thread).我在FrontEnd的init函數中定義了很多QLabel,都可以正常工作.

                  I am having a strange issue with PyQt5 in Python 3.5. I have two classes, FrontEnd(QWidget) and TimerThread(Thread). I have a number of QLabels defined in the init function of FrontEnd, all of which work properly.

                  顯示的是FrontEnd的相關幾個函數:

                  Shown are the relevant few functions of FrontEnd:

                  def update_ui(self):
                      ret, frame = self.cam_capture.read()
                  
                      if self.results_pending:
                          if not path.isfile('output.jpg'):
                              self.results_pending = False
                              with open('.out') as content_file:
                                  content = content_file.readlines()[2:-2]
                              system('rm .out')
                              self.handle_image_classification(content)
                  
                      if self.take_picture:
                          cv2.imwrite('output.jpg', frame)
                          self.user_prompt.setText('Please wait...')
                          system('./classifyimage.py --mean mean.binaryproto --nogpu --labels labels.txt model.caffemodel deploy.prototxt output.jpg > .out && rm output.jpg')
                          self.take_picture = False
                          self.results_pending = True
                  
                      image = QImage(frame, frame.shape[1], frame.shape[0], QImage.Format_RGB888).rgbSwapped()
                      pix = QPixmap.fromImage(image)
                      self.video_frame.setPixmap(pix)
                  
                  def update_bar_graph(self, data):
                      palette = QPalette()
                      palette.setColor(QPalette.Background, Qt.white)
                      for i in range(0, 8):
                          self.bar_graph_labels[i].setText(str(data[i]) + "%")
                          height = int(data[i] * 5)
                          self.bar_graph[i].setFixedSize(self.bar_width, height)
                          self.bar_graph[i].move(1280 + (i * (self.bar_width + self.bar_spacing)), 640 - height)
                  
                  def handle_image_classification(self, raw_output):
                      data = [None] * 8
                      for i in range(0, len(raw_output)):
                          raw_output[i] = raw_output[i].strip()
                          data[int(raw_output[i][-2]) - 1] = float(raw_output[i][:-10])
                      self.update_bar_graph(data)
                  

                  還有整個 TimerThread 類:

                  And the entire TimerThread class:

                  class TimerThread(Thread):
                      front_end = None
                  
                      def __init__(self, event):
                          Thread.__init__(self)
                          self.stopped = event
                  
                      def run(self):
                          while not self.stopped.wait(0.02):    
                              FrontEnd.update_ui(self.front_end)
                  

                  (TimerThreadfront_end 元素在 FrontEnd 的 init 上設置)

                  (The front_end element of TimerThread is set on init of FrontEnd)

                  問題出在 update_bar_graph 函數中.當 setFixedSize 調用被注釋掉時,程序運行良好,盡管在我的應用程序中沒有正確顯示條形圖的條(它們是 QLabels).move 函數似乎運行正常.但是,setFixedSize 調用會導致此錯誤:

                  The problem is in the update_bar_graph function. When the setFixedSize call is commented out, the program runs fine, although without properly displaying the bars of the bar graph in my application (which are QLabels). The move function seems to run properly. However, the setFixedSize call causes this error:

                  QObject::startTimer: Timers cannot be started from another thread
                  QObject::startTimer: Timers cannot be started from another thread
                  QObject::killTimer: Timers cannot be stopped from another thread
                  QObject::startTimer: Timers cannot be started from another thread
                  

                  我完全不知道為什么會發生這種情況,也不知道為什么 move 函數在本質上看起來很相似,但運行良好.任何幫助將非常感激.(如果我應該使用不同類型的計時器類或不同的方法在 PyQt 中繪制大矩形,我愿意接受任何此類建議).

                  I have absolutely no idea why this occurs, and why the move function, seemingly similar in nature, works fine. Any help would be much appreciated. (If I should be using a different sort of timer class or different methods for drawing large rectangles in PyQt, I am open to any such suggestions).

                  這是一些奇怪的東西.第二天我運行了兩次,沒有更改代碼.(我認為...)有一次條形圖沒有顯示,但沒有引發錯誤.另一次我得到了這個:

                  This is some weird stuff. I ran it twice the next day, with no changes to the code. (I think...) One time the bar graphs did not display but no errors were thrown. The other time I got this:

                  7fdfaf931000-7fdfaf932000 r--p 0007a000 08:07 655633                     /usr/lib/x86_64-linux-gnu/libQt5DBus.so.5.5.1
                  7fdfaf932000-7fdfaf933000 rw-p 0007b000 08:07 655633                     /usr/lib/x86_64-linux-gnu/libQt5DBus.so.5.5.1
                  7fdfaf933000-7fdfaf934000 rw-p 00000000 00:00 0 
                  7fdfaf934000-7fdfaf971000 r-xp 00000000 08:07 667112                     /usr/lib/x86_64-linux-gnu/libxkbcommon.so.0.0.0
                  7fdfaf971000-7fdfafb70000 ---p 0003d000 08:07 667112                     /usr/lib/x86_64-linux-gnu/libxkbcommon.so.0.0.0
                  7fdfafb70000-7fdfafb72000 r--p 0003c000 08:07 667112                     /usr/lib/x86_64-linux-gnu/libxkbcommon.so.0.0.0
                  7fdfafb72000-7fdfafb73000 rw-p 0003e000 08:07 667112                     /usr/lib/x86_64-linux-gnu/libxkbcommon.so.0.0.0
                  7fdfafb73000-7fdfafb7a000 r-xp 00000000 08:07 667110                     /usr/lib/x86_64-linux-gnu/libxkbcommon-x11.so.0.0.0
                  7fdfafb7a000-7fdfafd79000 ---p 00007000 08:07 667110                     /usr/lib/x86_64-linux-gnu/libxkbcommon-x11.so.0.0.0
                  

                  我想我可能在 PyQt5 中發現了一個錯誤.

                  I think I may have found a bug in PyQt5.

                  推薦答案

                  正如@mata 所述,您的代碼不是線程安全.這可能是錯誤行為的來源,當然應該在進一步調試之前修復(this 是相關的).

                  As mentioned by @mata your code is not thread safe. This is likely where the errant behaviour is coming from, and should certainly be fixed before debugging further (this is related).

                  它是線程不安全的原因是因為您直接從輔助線程與 GUI 對象交互.相反,您應該從線程向主線程中的插槽發出信號,您可以在其中安全地更新 GUI.但是,這需要您使用 QThread,無論如何根據這篇文章推薦.

                  The reason it is thread unsafe is because you are interacting with GUI objects from the secondary thread directly. You should instead emit a signal from your thread to a slot in the main thread where you can safely update your GUI. This however requires you use a QThread which is recommended anyway as per this post.

                  這需要進行以下更改:

                  class TimerThread(QThread):
                      update = pyqtSignal()
                  
                      def __init__(self, event):
                          QThread.__init__(self)
                          self.stopped = event
                  
                      def run(self):
                          while not self.stopped.wait(0.02):    
                              self.update.emit()
                  
                  class FrontEnd(QWidget):
                      def __init__(self):
                          super().__init__()
                  
                          ... # code as in your original
                  
                          stop_flag = Event()    
                          self.timer_thread = TimerThread(stop_flag)
                          self.timer_thread.update.connect(self.update_ui)
                          self.timer_thread.start()
                  

                  我還修改了您的代碼,以便它將對 TimerThread 的引用存儲在 FrontEnd 對象中,這樣線程就不會被垃圾回收.

                  I've also modified your code so that it stores a reference to the TimerThread in the FrontEnd object so the thread is not garbage collected.

                  我還要補充一點,這是每 0.02 秒觸發一次更新的一種過于復雜的方式.您可以使用 QTimer 來調用 update_ui 方法并完全放棄線程,但我采用的方法是您以后可能希望對線程執行更復雜的操作,所以已經演示了如何安全地做到這一點!

                  I would also add that this is an overly complex way of triggering an update every 0.02 seconds. You could use a QTimer to just call the update_ui method and ditch threads entirely but I'm taking the approach that you will likely want to do something more complex with your threads later, so have demonstrated how to do it safely!

                  這篇關于PyQt5“定時器不能從另一個線程啟動"更改 QLabel 的大小時出錯的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How to bind a function to an Action from Qt menubar?(如何將函數綁定到 Qt 菜單欄中的操作?)
                  PyQt progress jumps to 100% after it starts(PyQt 啟動后進度躍升至 100%)
                  How to set yaxis tick label in a fixed position so that when i scroll left or right the yaxis tick label should be visible?(如何將 yaxis 刻度標簽設置在固定位置,以便當我向左或向右滾動時,yaxis 刻度標簽應該可見
                  `QImage` constructor has unknown keyword `data`(`QImage` 構造函數有未知關鍵字 `data`)
                  Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                  How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時顯示進度條?)
                  • <bdo id='mboYs'></bdo><ul id='mboYs'></ul>
                        <tbody id='mboYs'></tbody>

                    • <small id='mboYs'></small><noframes id='mboYs'>

                        <i id='mboYs'><tr id='mboYs'><dt id='mboYs'><q id='mboYs'><span id='mboYs'><b id='mboYs'><form id='mboYs'><ins id='mboYs'></ins><ul id='mboYs'></ul><sub id='mboYs'></sub></form><legend id='mboYs'></legend><bdo id='mboYs'><pre id='mboYs'><center id='mboYs'></center></pre></bdo></b><th id='mboYs'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='mboYs'><tfoot id='mboYs'></tfoot><dl id='mboYs'><fieldset id='mboYs'></fieldset></dl></div>

                      1. <legend id='mboYs'><style id='mboYs'><dir id='mboYs'><q id='mboYs'></q></dir></style></legend>
                            <tfoot id='mboYs'></tfoot>

                            主站蜘蛛池模板: 国产精品xxxx | 欧美日韩在线视频一区二区 | 欧美精品一区二区三区在线播放 | 麻豆a级片 | 亚洲一区视频在线 | 黄色网址在线播放 | 在线观看亚洲欧美 | 久免费视频 | 99re热精品视频 | 欧美日韩在线播放 | 国产在线精品一区二区三区 | 午夜影院在线观看视频 | 水蜜桃亚洲一二三四在线 | 亚洲成人中文字幕 | 男人的天堂在线视频 | 成人在线免费视频 | 国产美女视频黄a视频免费 国产精品福利视频 | 成人在线中文字幕 | 在线成人av | 成人亚洲精品久久久久软件 | 久久久av | 国产高清在线 | 在线视频 亚洲 | 国产精品18久久久久久白浆动漫 | 免费观看www | 中文字幕在线剧情 | 国产乱码精品1区2区3区 | av国产精品| 国产视频一区在线 | 91精品国产乱码麻豆白嫩 | 日韩在线| 国产精品高潮呻吟久久av野狼 | 999久久久久久久久6666 | 韩国精品在线观看 | 国产精品久久久久久久久图文区 | 香蕉视频黄色 | 欧美精品一区二区免费 | 99精品99 | 国产精品久久久久久久久久久久午夜片 | 久操伊人 | 国产激情小视频 |