You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<divclass="textblock"><p>Examples are available in the <b>examples</b> directory. The PyScriptingConsole implements a simple interactive scripting console that shows how to script a simple application. The PyLauncher application can be used to run arbitrary <aclass="el" href="classPythonQt.html" title="The main interface to the Python Qt binding, realized as a singleton.">PythonQt</a> scripts given on the commandline.</p>
<p>The following shows a simple example on how to integrate <aclass="el" href="classPythonQt.html" title="The main interface to the Python Qt binding, realized as a singleton.">PythonQt</a> into your Qt application:</p>
<divclass="fragment"><divclass="line"><spanclass="preprocessor">#include "<aclass="code" href="PythonQt_8h.html">PythonQt.h</a>"</span></div><divclass="line"><spanclass="preprocessor">#include <QApplication></span></div><divclass="line">...</div><divclass="line"></div><divclass="line">int main( <spanclass="keywordtype">int</span> argc, <spanclass="keywordtype">char</span> **argv )</div><divclass="line">{</div><divclass="line"></div><divclass="line"> QApplication qapp(argc, argv);</div><divclass="line"></div><divclass="line"><spanclass="comment">// init PythonQt and Python itself</span></div><divclass="line"><aclass="code" href="classPythonQt.html#a2cc06e2e12ebd389504e3ce6a1751c3e">PythonQt::init</a>();</div><divclass="line"></div><divclass="line"><spanclass="comment">// get a smart pointer to the __main__ module of the Python interpreter</span></div><divclass="line"><aclass="code" href="classPythonQtObjectPtr.html">PythonQtObjectPtr</a> context = <aclass="code" href="classPythonQt.html#a55184a6cb954afb65e2d6f9ae56b0b0a">PythonQt::self</a>()-><aclass="code" href="classPythonQt.html#a95f68cbdfb7503b40361c6967e241de4">getMainModule</a>();</div><divclass="line"></div><divclass="line"><spanclass="comment">// add a QObject as variable of name "example" to the namespace of the __main__ module</span></div><divclass="line"> PyExampleObject example;</div><divclass="line"> context.<aclass="code" href="classPythonQtObjectPtr.html#ad426791e132d2c742ccee090cdb42c63">addObject</a>(<spanclass="stringliteral">"example"</span>, &example);</div><divclass="line"></div><divclass="line"><spanclass="comment">// do something</span></div><divclass="line"> context.<aclass="code" href="classPythonQtObjectPtr.html#ab03db3b8223905f2c01b0fe7999ac63a">evalScript</a>(<spanclass="stringliteral">"print example"</span>);</div><divclass="line"> context.<aclass="code" href="classPythonQtObjectPtr.html#ab03db3b8223905f2c01b0fe7999ac63a">evalScript</a>(<spanclass="stringliteral">"def multiply(a,b):\n return a*b;\n"</span>);</div><divclass="line"> QVariantList args;</div><divclass="line"> args << 42 << 47;</div><divclass="line"> QVariant result = context.<aclass="code" href="classPythonQtObjectPtr.html#af117195ba9e7ec9c9998ce8471da7e14">call</a>(<spanclass="stringliteral">"multiply"</span>, args);</div><divclass="line"> ...</div></div><!-- fragment --></div></div><!-- PageDoc -->
</div><!-- contents -->
<!-- start footer part -->
<hrclass="footer"/><addressclass="footer"><small>
Generated on Mon Jun 24 2019 11:13:44 for PythonQt by  <ahref="http://www.doxygen.org/index.html">