解决AI编写Pt6界面时的一些问题(持续更新)


问题1:使用pt5或其他形式的一些代码
报错:
‘QDropEvent’ object has no attribute ‘pos’

解释:

在 PyQt6 中 pos() 方法已被重命名为 position()(返回 QPointF 类型),而AI仍在使用 PyQt5 中的 pos() 方法,导致属性不存在错误。

解决方法:
找到代码中发生错误的函数,将 event.pos() 替换为 event.position().toPoint()(先将 QPointF 转为 QPoint,确保与 childAt 方法的参数类型匹配):

问题2:调用函数时将函数存储字典误当作对象使用

代码中的字典如下:

self.ai_functions = {
    "upload_local_file_to_oss": upload_local_file_to_oss,
    "top_replacement": top_replacement,
    ...
}

但是调用代码为:

self.ai_functions.upload_local_file_to_oss

解释:
访问时错误使用 dict.属性名 而非 dict["键名"],导致 Python 提示 “字典没有该属性”

报错:’dict’ object has no attribute ‘upload_local_file_to_oss’

修复:
使用以下类似代码:

 self.ai_functions["upload_local_file_to_oss"]


发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注