PythonQt不';不要打印任何东西

PythonQt不';不要打印任何东西,python,c++,qt,python-embedding,pythonqt,Python,C++,Qt,Python Embedding,Pythonqt,我将在上学习这些示例,但是PythonQt不会在控制台上打印任何内容。我执行一个脚本,只打印hello,但没有打印任何内容 PythonQt::init(); PythonQtObjectPtr context = PythonQt::self()->getMainModule(); context.evalScript("print 'hello'\n"); 另一方面,如果我使用纯python嵌入来执行它,它就会工作,并且hello会被打印出来: Py_Initialize(); Py

我将在上学习这些示例,但是PythonQt不会在控制台上打印任何内容。我执行一个脚本,只打印
hello
,但没有打印任何内容

PythonQt::init();
PythonQtObjectPtr context = PythonQt::self()->getMainModule();
context.evalScript("print 'hello'\n");
另一方面,如果我使用纯python嵌入来执行它,它就会工作,并且
hello
会被打印出来:

Py_Initialize();
PyRun_SimpleString("print 'hello'\n");
有趣的是,如果我添加
PythonQt::init()
Py_Initialize()之前,不会再次打印任何内容。所以我假设
PythonQt::init()
对python的控制台输出执行一些操作。它是否以某种方式重定向了它?我怎么把它打印出来

我使用的是Qt4.8.6、PythonQt2.1和Python2.7.6。

阅读后,似乎
PythonQt::init()将python输出重定向到PythonQt::pythonStdOut信号

这是因为默认情况下,
PythonQt::init()
声明集
RedirectStdOut

static void init(int flags = IgnoreSiteModule | RedirectStdOut, const QByteArray& pythonQtModuleName = QByteArray());
因此,这一点现在起作用了:

PythonQt::init(PythonQt::IgnoreSiteModule);
PythonQtObjectPtr context = PythonQt::self()->getMainModule();
context.evalScript("print 'hello'\n");
或者,我可以连接信号:

QObject::connect(PythonQt::self(), SIGNAL(pythonStdOut(const QString&)), this, SLOT(Print(const QString&)));
阅读之后,似乎
PythonQt::init()将python输出重定向到PythonQt::pythonStdOut信号

这是因为默认情况下,
PythonQt::init()
声明集
RedirectStdOut

static void init(int flags = IgnoreSiteModule | RedirectStdOut, const QByteArray& pythonQtModuleName = QByteArray());
因此,这一点现在起作用了:

PythonQt::init(PythonQt::IgnoreSiteModule);
PythonQtObjectPtr context = PythonQt::self()->getMainModule();
context.evalScript("print 'hello'\n");
或者,我可以连接信号:

QObject::connect(PythonQt::self(), SIGNAL(pythonStdOut(const QString&)), this, SLOT(Print(const QString&)));