当前位置: 首页 > wzjs >正文

做网站毕设任务书购物网站制作

做网站毕设任务书,购物网站制作,网站素材设计框架,做a爱片网站文章目录 1 找不到资源文件2 使用subprocess执行时有黑色弹窗3 找不到exec4 pyside6-project lupdate的bug5 找不到pyd模块6 pyd模块编码错误7 运行显示Qt platform plugin "windows" in "8 tr()包含的字符串无法被翻译 更多精彩内容👉内容导航 &…

文章目录

      • 1 找不到资源文件
      • 2 使用subprocess执行时有黑色弹窗
      • 3 找不到exec
      • 4 pyside6-project lupdate的bug
      • 5 找不到pyd模块
      • 6 pyd模块编码错误
      • 7 运行显示`Qt platform plugin "windows" in "`
      • 8 `tr()`包含的字符串无法被翻译


更多精彩内容
👉内容导航 👈
👉Qt开发 👈
👉python开发 👈

1 找不到资源文件

使用rcc将qrc文件编译为py文件后,找不到资源文件可能是因为使用的是python原生的函数,这里是一个大坑,例如:

print(QFile.exists(":/style/style.css"))   # true
print(os.path.exists(":/style/style.css")) # false
# 打开失败
with open(":/style.css", "r") as f:app.setStyleSheet(f.read())  # 设置样式表

2 使用subprocess执行时有黑色弹窗

  • 如下所示,可通过shell=True指定使用shell执行,不会出现弹窗。

    ret = subprocess.run(['adb', 'connect', '127.0.0.1:7555'], shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    

3 找不到exec

错误信息:

Traceback (most recent call last):File "E:\Code\py\PythonProject\main.py", line 27, in <module>sys.exit(app.exec())
AttributeError: 'PySide2.QtWidgets.QApplication' object has no attribute 'exec'

解决办法:

  • PySide2中使用的是sys.exit(app.exec_()),PySide6使用的是sys.exit(app.exec())

4 pyside6-project lupdate的bug

  • 使用pyside6-project lupdate命令可以在pyside6中生成翻译使用的ts文件,但是有时候我们想将ts文件放在子文件夹下,却发现无法实现;

  • 并且使用pyside6-project lupdate命令无法清除已经失效的文本;

  • 这是因为pyside6-project lupdate中使用的是ts文件名,不包含路径,所以就是在工程路径下,并且有几个ts文件就会执行几次。

    (.venv) PS E:\Code\py\Test> pyside6-project.exe lupdate
    pyside6-lupdate main.py mainwindow.py TableWidget.py mainwindow.ui logwidget.ui control.ui -ts Test_zh_CN.ts
    
  • 实现代码如下所示:for用来遍历ts文件,有几个ts文件就会调用run_command()执行几次。

    cmd_prefix.append("-ts")for ts_file in self.project.ts_files:if requires_rebuild(source_files, ts_file):cmd = cmd_prefixcmd.append(ts_file.name)run_command(cmd, cwd=project_dir)
    
  • 解决办法:打开.venv\Lib\site-packages\PySide6\scripts\project.py文件,在def lupdate(self)函数中修改为下面所示代码。

    def lupdate(self):for sub_project_file in self.project.sub_projects_files:Project(project_file=sub_project_file).lupdate()if not self.project.ts_files:print(f"{self.project.project_file.name}: No .ts file found.",file=sys.stderr)returnsource_files = self.project.python_files + self.project.ui_filesproject_dir = self.project.project_file.parentcmd_prefix = [LUPDATE_CMD] + [os.fspath(p.relative_to(project_dir)) for p in source_files]cmd_prefix.append("-ts")ts_files = []for ts_file in self.project.ts_files:if requires_rebuild(source_files, ts_file):ts_dir = ts_file.parentif not ts_dir.exists():ts_dir.mkdir(parents=True, exist_ok=True)ts_files.append(ts_file.resolve().as_posix())if ts_files:cmd = cmd_prefix;cmd.extend(ts_files)cmd.append("-no-obsolete") # 清除失效文本run_command(cmd, cwd=project_dir)
    
  • 运行结果如下所示:会将ts文件生成到指定路径中,并且只执行一次。

    (.venv) PS E:\Code\py\Test> pyside6-project.exe lupdate
    pyside6-lupdate main.py mainwindow.py TableWidget.py mainwindow.ui logwidget.ui control.ui -ts E:/Code/py/Test/Language/Test_zh_CN.ts E:/Code/py/Test/Language/Test_en_US.ts
    

5 找不到pyd模块

  • 可能是python版本不一致,例如pyd是使用python3.12编译,使用python3.8导入就找不到。
  • 如果PYBIND11_MODULE中设置的模块名称和pybind11_add_module指定编译生成的名称不同也找不到。

6 pyd模块编码错误

  • python默认使用utf-8编码,如果使用pybind11导出的cpp文件使用的是其他编码,则生成的pyd模块导入时会报错。
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb2 in position 5: invalid start byteThe above exception was the direct cause of the following exception:Traceback (most recent call last):File "E:\Code\py\PythonProject1\main.py", line 1, in <module>import pcba_plugin
ImportError: initialization failed

7 运行显示Qt platform plugin "windows" in "

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.
  • 解决办法:路径不要有中文名。

8 tr()包含的字符串无法被翻译

  • 在PySide6中,self.tr() 方法用于翻译字符串。

  • 如果你发现 self.tr(f"中文{test}") 这样的格式无法被翻译,可能是因为Qt的翻译系统无法识别这种格式的字符串。

  • Qt的翻译工具(如 lupdate)通常需要字符串是静态的,以便能够提取这些字符串进行翻译。

  • 解决办法,改为:

    self.tr("设备{arg}已离线:").format(arg=text)
    # 或者
    self.tr("发现新设备:") + device
    


http://www.dtcms.com/wzjs/428400.html

相关文章:

  • 自己怎样建网站做微商sem竞价外包公司
  • 乌鲁木齐网站设计seo网站推广助理
  • 个人可以做招聘网站吗百度百科推广联系方式
  • 想要网站推广页面不受国内限制的浏览器下载
  • 塑胶包装东莞网站建设西安网站关键词优化推荐
  • 湖州 网站建设公司长沙网站优化指导
  • 遵义公司做网站找哪个公司好广安网站seo
  • 博客网站日志页面代码优化大师下载安装app
  • 网站建设教学工作总结网站推广的方法有哪些?
  • 免注册个人网站制作百度首页的ip地址
  • 北京常用网站市场营销策划
  • dreamweaver cc下载乐云seo官网
  • 西安网站建设产品福州seo排名优化
  • 成都游戏网站开发今日国际新闻最新消息大事
  • 聊城网站建设信息惠州seo网络推广
  • 网站建设哪里有廊坊优化外包
  • 双语网站价格国内哪个搜索引擎最好用
  • 网上银行官网优化公司网站排名
  • 网站结构该怎么做广东东莞疫情最新情况
  • 装修推广网站哪个好数据分析师报考官网
  • 广东省住房和建设局官方网站网络营销推广的方法有哪些
  • 蚌埠网站建设哪家好nba中国官方网站
  • 黔东南建设厅网站故事型软文广告
  • 河北高阳做网站的优秀网站网页设计分析
  • 提供秦皇岛网站建设哪里有泉州seo托管
  • 政府网站集约化建设领导小组如何被百度收录
  • 哈尔滨小程序开发制作公司优化课程设置
  • 株洲网站建设公司域名注册商怎么查
  • 如何在万网建设网站seo怎么优化效果更好
  • 阿里备案成功后怎么做网站广州关键词快速排名