Menu

Having multiple instance of PythonQt instead singleton instance

Help
Edvard
2017-05-16
2017-05-16
  • Edvard

    Edvard - 2017-05-16

    For some reason I need to have multiple instance of pythonQt in my application but PythonQt does not let to have multiple instance. So I want to know is there any solution for having multiple instance of pythonQt in the application?

     

    Last edit: Edvard 2017-05-16
  • Florian Link

    Florian Link - 2017-05-16

    There can only be one instance of PythonQt and there can only be one Python interpreter(in the same process).
    You should use the same PythonQt singleton everywhere and put each part that you want to execute in it's own module, so that the parts don't interfere. There is an Api to create a new module on the PythonQt singleton.

     
    • Edvard

      Edvard - 2017-05-16

      Thanks for your answering, so can you tell me witch API creates a new module?

       

      Last edit: Edvard 2017-05-16
  • Florian Link

    Florian Link - 2017-05-16
    PythonQtObjectPtr   createModuleFromFile (const QString &name, const QString &filename)
    
    PythonQtObjectPtr   createModuleFromScript (const QString &name, const QString &script=QString())
    
    PythonQtObjectPtr   createUniqueModule ()
    
     
  • Andrewc

    Andrewc - 2017-05-26

    HI Florian, I have a related question. I embed Python/PythonQT in an application - as you can imagine I have a "Run Script" option.
    At the moment I am using the Python "C" API PyRun_SimpleString. I would like to (optionally) run the script in a "clean" Python environment - that is with no side-effects of previous runs of other scripts. Is that possible using the PythonQT API.

     
    • Florian Link

      Florian Link - 2017-05-26

      Yes, just create a new module for each run and execute your code inside of
      the module. Alternatively you can also run code inside of a dict, but that
      is more complicated because you need to add builtins to the dict.
      On Fri, 26 May 2017 at 20:09, Andrewc andrewc8@users.sf.net wrote:

      HI Florian, I have a related question. I embed Python/PythonQT in an
      application - as you can imagine I have a "Run Script" option.
      At the moment I am using the Python "C" API PyRun_SimpleString. I would
      like to (optionally) run the script in a "clean" Python environment - that
      is with no side-effects of previous runs of other scripts. Is that possible
      using the PythonQT API.


      Having multiple instance of PythonQt instead singleton instance


      Sent from sourceforge.net because you indicated interest in <
      https://sourceforge.net/p/pythonqt/discussion/631393/>

      To unsubscribe from further messages, please visit <
      https://sourceforge.net/auth/subscriptions/>

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.