久久久久久久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>

        裝飾器添加了一個意想不到的參數(shù)

        Decorator adds an unexpected argument(裝飾器添加了一個意想不到的參數(shù))
      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'>

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

                  問題描述

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

                  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!")
                  

                  運行時出現(xiàn)以下異常:

                  fun() takes 1 positional argument but 2 were given
                  

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

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

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

                  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)
                  

                  所以默認情況下它會發(fā)送一個 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!")
                  

                  這篇關(guān)于裝飾器添加了一個意想不到的參數(shù)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  How to bind a function to an Action from Qt menubar?(如何將函數(shù)綁定到 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 刻度標簽設(shè)置在固定位置,以便當我向左或向右滾動時,yaxis 刻度標簽應(yīng)該可見
                  `QImage` constructor has unknown keyword `data`(`QImage` 構(gòu)造函數(shù)有未知關(guān)鍵字 `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>

                          • 主站蜘蛛池模板: 97精品超碰一区二区三区 | 国产精品不卡一区 | 一区二区三区视频在线观看 | 中国人pornoxxx麻豆 | 久久成人免费视频 | 麻豆亚洲 | 精品国产一区二区三区成人影院 | 国产高清视频一区二区 | 亚洲精品99| 嫩草最新网址 | 久久婷婷av | 亚洲精品久久久久中文字幕二区 | 在线看av的网址 | 华人黄网站大全 | 日韩欧美国产一区二区三区 | 精品欧美一区二区精品久久 | 九九视频在线观看视频6 | 日韩精品影院 | 欧美一级片免费看 | 欧美成人精品激情在线观看 | 精品毛片 | 伊人网站在线 | 亚洲精品一区在线观看 | 天天插天天狠天天透 | 国产精品视频网 | 91看片网| 日韩在线播放网址 | 久久免费资源 | 精品欧美乱码久久久久久 | 91精品久久久久久久久久入口 | 啪啪网页| 亚洲毛片 | 色伊人久久 | www久久久 | 精品免费国产视频 | 日韩欧美国产一区二区 | 天天干天天干 | 色婷婷综合久久久中文字幕 | 久久精品国产久精国产 | 久久久久久国产精品免费免费 | 99久久精品免费看国产免费软件 |