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

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

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

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

        <legend id='wJYmz'><style id='wJYmz'><dir id='wJYmz'><q id='wJYmz'></q></dir></style></legend>

        qApp 與 QApplication.instance()

        qApp versus QApplication.instance()(qApp 與 QApplication.instance())
          • <bdo id='QF1a4'></bdo><ul id='QF1a4'></ul>
          • <small id='QF1a4'></small><noframes id='QF1a4'>

            <tfoot id='QF1a4'></tfoot>

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

                  本文介紹了qApp 與 QApplication.instance()的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  使用 PyQt5,這兩個都返回應用程序對象:

                  With PyQt5, both of these return the application object:

                  app = QtWidgets.QApplication.instance()
                  app = QtWidgets.qApp
                  for i in app.arguments()[1:]:
                      ...
                  

                  但是為什么print(QtWidgets.QApplication.instance() is QtWidgets.qApp) print False?

                  But why does print(QtWidgets.QApplication.instance() is QtWidgets.qApp) print False?

                  推薦答案

                  QtWidgets.QApplication.instance()QtWidgets.qApp的區別在于后者是一個靜態模塊變量,必須在第一次導入模塊時創建.這會導致以下最初令人困惑的行為:

                  The difference between QtWidgets.QApplication.instance() and QtWidgets.qApp is that the latter is a static module variable that must be created when the module is first imported. This results in the following initially baffling behaviour:

                  >>> from PyQt5 import QtWidgets
                  >>> inst = QtWidgets.QApplication.instance()
                  >>> qapp = QtWidgets.qApp
                  >>> (inst, qapp)
                  (None, <PyQt5.QtWidgets.QApplication object at 0x7ff3c8bd3948>)
                  

                  因此,即使尚未創建 QApplication 對象,qApp 變量仍然指向 QApplication 實例.如果模塊更像類,因此它們可以具有動態屬性,那么 qApp 可能會像 QApplication.instance() 一樣工作并最初返回 .但是因為它是靜態的,所以它必須始終返回一個正確類型的對象,以便它以后可以引用與 QApplication.instance() 相同的底層 C++ 對象.

                  So even though no QApplication object has been created yet, the qApp variable still points to a QApplication instance. If modules were more like classes, so that they could have dynamic properties, it would be possible for qApp to work exactly like QApplication.instance() does and initially return None. But because it is static, it must always return an object of the correct type, so that it can later refer to the same underlying C++ object as QApplication.instance().

                  然而,重要的是要注意 qApp 最初只是一個 empty 包裝器:

                  However, it's important to note that qApp is initially just an empty wrapper:

                  >>> qapp.objectName()
                  Traceback (most recent call last):
                    File "<stdin>", line 1, in <module>
                  RuntimeError: wrapped C/C++ object of type QApplication has been deleted
                  

                  一旦創建了 QApplication,它們都會指向同一個東西:

                  Once the QApplication is created, though, they will both point to the same thing:

                  >>> app = QtWidgets.QApplication([])
                  >>> app.setObjectName('foo')
                  >>> qapp.objectName()
                  'foo'
                  

                  所以 (QtWidgets.QApplication.instance() is QtWidgets.qApp) 返回 False 的原因是,這兩個對象是圍繞相同底層的不同 python 包裝器C++ 對象.

                  So the reason why (QtWidgets.QApplication.instance() is QtWidgets.qApp) returns False, is that the two objects are different python wrappers around the same underlying C++ object.

                  如果您需要創建自己的 QApplication 子類,但仍想使用 qApp,請務必注意這一點:

                  It's important to be aware of this point if you ever need to create your own sublass of QApplication, but still want to use qApp:

                  >>> from PyQt5 import QtWidgets
                  >>> class MyApp(QtWidgets.QApplication):
                  ...     def hello(self): print('Hello World')
                  ...
                  >>> myapp = MyApp([])
                  >>> myapp.hello()
                  Hello World
                  >>>
                  >>> QtWidgets.qApp
                  <PyQt5.QtWidgets.QApplication object at 0x7f5e42f40948>
                  >>> QtWidgets.qApp.hello()
                  Traceback (most recent call last):
                    File "<stdin>", line 1, in <module>
                  AttributeError: 'QApplication' object has no attribute 'hello'
                  >>>
                  >>> inst = QtWidgets.QApplication.instance()
                  >>> inst
                  <__main__.MyApp object at 0x7f5e42f409d8>
                  >>> inst.hello()
                  Hello World
                  

                  解決這個問題的唯一方法是顯式覆蓋 qApp 模塊變量(并且顯然要確保在其他模塊可以導入之前完成此操作):

                  The only way around this is to explicitly overwrite the qApp module variable (and obviously ensure that this is done before it can be imported by other modules):

                  >>> QtWidgets.qApp = myapp
                  >>> QtWidgets.qApp.hello()
                  Hello World
                  

                  這篇關于qApp 與 QApplication.instance()的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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='BVwFc'></bdo><ul id='BVwFc'></ul>
                  • <small id='BVwFc'></small><noframes id='BVwFc'>

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

                  • <legend id='BVwFc'><style id='BVwFc'><dir id='BVwFc'><q id='BVwFc'></q></dir></style></legend>
                        <tbody id='BVwFc'></tbody>

                      <tfoot id='BVwFc'></tfoot>

                          1. 主站蜘蛛池模板: 精品国产鲁一鲁一区二区张丽 | 久国产精品 | av大片在线| 在线国产99 | 亚洲免费在线 | 久久www免费人成看片高清 | 欧美一级二级在线观看 | 黄色在线免费播放 | 在线视频国产一区 | 全部免费毛片在线播放网站 | 你懂的在线视频播放 | 麻豆av一区二区三区久久 | 久www| 国产a级毛毛片 | 91视视频在线观看入口直接观看 | 天堂一区二区三区 | 日韩a视频 | 久久精品黄色 | 国产一区二区精品在线观看 | 日本久久久久久 | 成人国产精品久久 | 久久亚洲视频网 | 黄色在线观看 | 欧美极品在线观看 | 日韩成人中文字幕 | 精品一区二区在线观看 | 国产日韩精品一区二区三区 | 亚洲视频一区二区三区 | 91亚洲精选 | 亚洲精品欧美精品 | 久草新在线 | 亚洲综合电影 | 精品永久 | 99热99| 国产精品久久99 | 亚洲成人精品在线观看 | 欧美一区不卡 | 一区二区三区亚洲精品国 | 成人精品免费视频 | 国产成人精品一区二区在线 | 精品美女视频在线观看免费软件 |