gpt4 book ai didi

python - QApplication 实例已经存在

转载 作者:太空狗 更新时间:2023-10-30 00:27:58 25 4
gpt4 key购买 nike

我正在 3Dsmax 2015 上做一些简单的 PySide。

这是我的错误:

python.ExecuteFile "C:\Program Files\Autodesk\3ds Max 2015\scripts\Python\demoUniTest.py"
-- Runtime error: Line 32 <module>()
<type 'exceptions.RuntimeError'> A QApplication instance already exists.

这是我的代码:

import sys
from PySide.QtCore import *
from PySide.QtGui import *
from math import *

class Form(QDialog):
def __init__(self,parent=None):
super(Form,self).__init__(parent)

self.browser = QTextBrowser()
self.lineedit = QLineEdit("Type an expression and press Enter")
self.lineedit.selectAll()

layout = QVBoxLayout()
layout.addWidget(self.browser)
layout.addWidget(self.lineedit)
self.setLayout(layout)

self.lineedit.setFocus()

self.connect(self.lineedit, SIGNAL("returnPressed()"),self.updateUi)
self.setWindowTitle("Calculate")

def updateUi(self):
try:
text = self.lineedit.text()
self.browser.append("%s = <b>%s</b>" % (text,eval(text)))
except:
self.browser.append("<font color=red>%s is invalid</font>" %text)

app = QApplication(sys.argv)

form = Form()

form.show()

app.exec_()

当我在 Pycharm 上使用这段代码时,我没有收到任何错误。只有当我在 3Dsmax 2015 Listener 上使用它时才会出现

最佳答案

帮助文件中的直接引用 ( Using PySide ):

Normally one creates a PySide application object in a script using QtGui.QApplication(). However, in 3ds Max, there is already a PySide application running, so you get a handle for that object like this:

QtGui.QApplication.instance()

关于python - QApplication 实例已经存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27150852/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com