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

<tfoot id='pE548'></tfoot>

    1. <small id='pE548'></small><noframes id='pE548'>

        <bdo id='pE548'></bdo><ul id='pE548'></ul>
    2. <legend id='pE548'><style id='pE548'><dir id='pE548'><q id='pE548'></q></dir></style></legend>

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

        裝飾器添加了一個意想不到的參數

        Decorator adds an unexpected argument(裝飾器添加了一個意想不到的參數)
      2. <legend id='TVnGK'><style id='TVnGK'><dir id='TVnGK'><q id='TVnGK'></q></dir></style></legend>
          <tbody id='TVnGK'></tbody>
          <bdo id='TVnGK'></bdo><ul id='TVnGK'></ul>
          <tfoot id='TVnGK'></tfoot>
              <i id='TVnGK'><tr id='TVnGK'><dt id='TVnGK'><q id='TVnGK'><span id='TVnGK'><b id='TVnGK'><form id='TVnGK'><ins id='TVnGK'></ins><ul id='TVnGK'></ul><sub id='TVnGK'></sub></form><legend id='TVnGK'></legend><bdo id='TVnGK'><pre id='TVnGK'><center id='TVnGK'></center></pre></bdo></b><th id='TVnGK'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='TVnGK'><tfoot id='TVnGK'></tfoot><dl id='TVnGK'><fieldset id='TVnGK'></fieldset></dl></div>
              • <small id='TVnGK'></small><noframes id='TVnGK'>

                  本文介紹了裝飾器添加了一個意想不到的參數的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我想在我的 PyQt5 應用程序中使用裝飾器來處理異常:

                  I wanted to use a decorator to handle exceptions in my PyQt5 application:

                  def handle_exceptions(func):
                      def func_wrapper(*args, **kwargs):
                          try:
                              print(args)
                              return func(*args, **kwargs)
                          except Exception as e:
                              print(e)
                              return None
                      return func_wrapper
                  
                  
                  class MainWindow(QMainWindow):
                  
                      def __init__(self):
                          QMainWindow.__init__(self)
                          loadUi("main_window.ui",self)
                          self.connect_signals() 
                  
                      def connect_signals(self):
                          self.menu_action.triggered.connect(self.fun)
                  
                      @handle_exceptions
                      def fun(self):
                          print("hello there!")
                  

                  運行時出現以下異常:

                  fun() takes 1 positional argument but 2 were given
                  

                  輸出為 False(在裝飾器中打印 args).

                  The output is False (printed args in the decorator).

                  有趣的是,當我在構造函數中直接通過 self.fun() 運行 fun() 函數或注釋裝飾器時,一切正常.似乎裝飾器添加了一個額外的參數,但僅在信號調用函數時.怎么回事?

                  The interesting thing is that when I run the fun() function directly by self.fun() in the constructor or comment the decorator, everything works. Seems like the decorator adds an additional argument, but only when the function is called by the signal. What is going on?

                  推薦答案

                  問題是因為triggered 信號超載,也就是說它有2個簽名:

                  The problem is caused because the triggered signal is overload, that is to say it has 2 signatures:

                  void QAction::triggered(bool checked = false)
                  

                  QAction.triggered()
                  QAction.triggered(bool checked)
                  

                  所以默認情況下它會發送一個 boolean(false) 顯然不接受導致錯誤的有趣"方法.

                  So by default it sends a boolean(false) that clearly does not accept the "fun" method causing the error.

                  在這種情況下,解決方案是使用 @pyqtSlot() 裝飾器來指明你必須接受的簽名:

                  In this case the solution is to use the @pyqtSlot() decorator to indicate the signature that you must accept:

                  @pyqtSlot()
                  @handle_exceptions
                  def fun(self):
                      print("hello there!")
                  

                  這篇關于裝飾器添加了一個意想不到的參數的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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時顯示進度條?)

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

                        <tbody id='I8sgf'></tbody>

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

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

                          • 主站蜘蛛池模板: 成年人毛片 | 欧美精品三区 | 日韩成人片| 国产欧美日韩在线 | 黄色小视频在线 | 黄色大毛片 | 午夜视频一区二区三区 | av网站免费在线观看 | 在线日韩一区 | 日韩精品在线看 | 国产h视频在线观看 | 欧美亚洲 | 色涩av | 一区二区三区久久 | 国产精品视频久久久 | 中文字幕国产在线 | 久久久久久久久久久国产 | 亚洲精品一二三四 | 国产高清成人 | 一区二区三区在线免费观看 | 日本欧美久久久久免费播放网 | www.午夜 | 激情五月综合色婷婷一区二区 | 成人午夜网站 | 成人欧美一区二区三区黑人免费 | 一级黄色小视频 | 日韩在线视频一区二区三区 | 在线观看a视频 | aaaaa毛片| 国产三级成人 | 成人免费网站 | 一级片网址 | 黄色片免费网站 | 538精品视频 | 天天干天天曰 | 九九热在线视频观看 | 一级性视频 | 成人福利在线观看 | 日韩在线视频观看 | 91久久国产综合久久 | 亚洲一区二区国产精品 |