PythonQt doesn't print anything
<p>I'm following the examples at <a href="http://pythonqt.sourceforge.net/Examples.html" rel="nofollow">http://pythonqt.sourceforge.net/Examples.html</a>, but PythonQt doesn't print anything on the console. I execute a script that just prints <code>hello</code>, but nothing gets printed.</p>

<pre><code>PythonQt::init();
PythonQtObjectPtr context = PythonQt::self()-&gt;getMainModule();
context.evalScript("print 'hello'\n");
</code></pre>

<p>On the other hand, if I execute it using plain python embedding it works and <code>hello</code> is printed:</p>

<pre><code>Py_Initialize();
PyRun_SimpleString("print 'hello'\n");
</code></pre>

<p>What's interesting is that if I add <code>PythonQt::init();</code> before <code>Py_Initialize();</code>, nothing gets printed again. So I assume <code>PythonQt::init();</code> does something to python's console output. Does it redirect it somehow? How do I make it print?</p>

<p>I'm on Qt 4.8.6, PythonQt 2.1, and Python 2.7.6.</p>

<p>After reading <a href="https://sourceforge.net/p/pythonqt/discussion/631393/thread/33ad915c" rel="nofollow">https://sourceforge.net/p/pythonqt/discussion/631393/thread/33ad915c</a>, it seems that <code>PythonQt::init();</code> does redirect python output to the PythonQt::pythonStdOut signal.</p>

<p>This is because <code>PythonQt::init()</code> declaration sets <code>RedirectStdOut</code> by default:</p>

<pre><code>static void init(int flags = IgnoreSiteModule | RedirectStdOut, const QByteArray&amp; pythonQtModuleName = QByteArray());
</code></pre>

<p>So this works now:</p>

<pre><code>PythonQt::init(PythonQt::IgnoreSiteModule);
PythonQtObjectPtr context = PythonQt::self()-&gt;getMainModule();
context.evalScript("print 'hello'\n");
</code></pre>

<p>Or alternatively, I could connect the signal:</p>

<pre><code>QObject::connect(PythonQt::self(), SIGNAL(pythonStdOut(const QString&amp;)), this, SLOT(Print(const QString&amp;)));
</code></pre>

python c++ qt python-embedding pythonqt