Qt for Python 5.12初体验

Posted 李建业

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Qt for Python 5.12初体验相关的知识,希望对你有一定的参考价值。

Qt for Python 5.12初体验

2018年12月18日,Qt在其博客上宣布Qt for Python 5.12正式发布,按照其帮助文档的说明,尝试运行了第一个小例子。
首先需要安装Python 3.5+ or 2.7和for Qt 5.12,安装完成之后边可以输入代码编译运行了。
复制自Qt示例的源代码如下:

1 import sys
2 from PySide2.QtWidgets import QApplication, QLabel
3 
4 app = QApplication(sys.argv)
5 label = QLabel("Hello World!")
6 label.show()
7 app.exec_()

编译运行,提示错误如下:
qt.qpa.plugin: Could not find the Qt platform plugin "windows" in ""
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
找不到插件的路径,这里是解决方案。修改之后的代码如下:

 1 import os
 2 import sys
 3 import PySide2
 4 from PySide2.QtWidgets import QApplication, QLabel
 5 
 6 dirname = os.path.dirname(PySide2.__file__)
 7 plugin_path = os.path.join(dirname, \'plugins\', \'platforms\')
 8 os.environ[\'QT_QPA_PLATFORM_PLUGIN_PATH\'] = plugin_path
 9 
10 app = QApplication(sys.argv)
11 label = QLabel("Hello World")
12 label.show()
13 sys.exit(app.exec_())

成功运行,并弹出对话框。

以上是关于Qt for Python 5.12初体验的主要内容,如果未能解决你的问题,请参考以下文章

Qt初体验

python flask初体验linux命令发射器

visual studio for mac的安装初体验

vs code初体验

visual studio for mac的安装初体验

python初体验