目前我正在使用pythonQt将python嵌入到我的qt应用程序中。我需要在我的qt应用程序中实现一个python控制台,用于处理用户python代码: input()或raw_input(),我必须在python中重定向stdin,所以我在我的类中定义了一个静态方法,显示一个模态输入对话框,返回文本用户输入:
static QString myClass::myStdIn(void *callData)
{
return QFileInputDialog::getText(NULL,....);
}
//then register it to PythonQt in myclass's construct method:
PythonQt::self().setRedirectStdInCallback(myClass::myStdIn,0);此方法的声明为:
void PythonQt::setRedirectStdInCallback (PythonQtInputChangedCB *callback,void *callbackData = 0)myClass::myStdIn seams必须是静态的,才能注册为callback.The问题是,当在python中调用input()或raw_input()时,应用程序会冻结。我尝试使用我自己的模式对话框来替换QFileInputDialog::getText(),但只要它是一个模式对话框,在执行input()之后,应用程序就会冻结并出错。
有人知道如何处理这个问题吗?谢谢
发布于 2016-03-01 11:56:38
你试过看PythonQtScriptingConsole吗?
connect(PythonQt::self(), SIGNAL(pythonStdOut(const QString&)), this, SLOT(stdOut(const QString&)));
connect(PythonQt::self(), SIGNAL(pythonStdErr(const QString&)), this, SLOT(stdErr(const QString&)));https://stackoverflow.com/questions/19769703
复制相似问题