一个QApplication实例已经存在 [英] A QApplication instance already exists
本文介绍了一个QApplication实例已经存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在3Dsmax 2015上做一些简单的PySide.
I'm doing some simple PySide on 3Dsmax 2015.
这是我的错误:
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_()
当我在Picharm上使用此代码时,没有任何错误.它仅在我在3Dsmax 2015侦听器上使用时出现
When I use this code on Picharm dont have any errors. It only appear when I use on 3Dsmax 2015 Listener
推荐答案
Direct citation from the helpfile (Using PySide):
通常,使用以下命令在脚本中创建PySide应用程序对象 QtGui.QApplication().但是,在3ds Max中,已经有一个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()
这篇关于一个QApplication实例已经存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文