Skip to content

seisgo/QtPythonEmbedding

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QtPythonEmbedding

Simple demonstrations about Python embedding in C++ project, implemented with Qt

It includes five different implementations of embedding:

  • Execuate simple string
  • Execuate simple file
  • Execuate certain function by set global path
  • Execuate certain function by module importing
  • Call embedded python interpreter

Test of simple python script file

  • The test python script file is runtest.py.
  • This implementation is stored in master branch.

NOTE: For rerunning, abosulte path of python script file should be modified.

Test of complex python project

  • To run some complex python project, I have tested a python project for video and image super-resolution processing, which is named as VideoSuperResolution.
  • I have made some modifications in main.cpp to execute main function in python project.
    • For complex python project, directories of imported non-Python-standard-library modules and sefl-defined modules should be added into search path.
    • What's more, if there is relative directory used in python project, we should make sure python script executing in its real path, not that of exectubale file in Qt project. Some pieces of codes can be inserted at the beginning of python main functoin, shown as:
      # 'import os' is needed
      script_path = os.path.realpath(__file__)
      script_dir = os.path.dirname(script_path)
      os.chdir(script_dir)

NOTE:

  • The implementation of complex python project is just a demonstration, to show the process and some tips about this type of implementation.
  • Since I have only uploaded main python script (named as run.py) of VideoSuperResolution project, and it depends on more relative python scripts and configuration files, this implementation can't be rerun successfully.
  • This implementation of running complex python project is forked in a branch repository, named as complexPythonProject, to avoid the rerunning failure.

About

Simple demonstrations about Python embedding in C++ project, implemented with Qt

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published