python - 在 PySide2 中使用 invokeMethod 时使用 QGenericArgument / Q_ARG
问题描述
我正在尝试将代码从 PyQt5 移植到 PySide2。在某个时刻,我正在使用:
QMetaObject.invokeMethod(dialog, "my_function", Qt.QueuedConnection, QGenericArgument.Q_ARG(str, filepath))
尽管如此,Q_ARG 并未进入 PySide2 中的 QGenericArgument。事实上,我根本无法找到它,尽管它在文档中被描述为要使用的宏而不是 QGenericArgument。
计划 B:我尝试直接使用 QGenericArgument,即使文档不鼓励这样做。因此我尝试了这些:
QMetaObject.invokeMethod(dialog, "my_function", Qt.QueuedConnection, QGenericArgument(str, filepath))
QMetaObject.invokeMethod(dialog, "my_function", Qt.QueuedConnection, QGenericArgument('str', filepath))
QMetaObject.invokeMethod(dialog, "my_function", Qt.QueuedConnection, QGenericArgument('QString', filepath))
在所有情况下,错误都是相同的:
ERROR: 'PySide2.QtCore.QGenericArgument' called with wrong argument types:
PySide2.QtCore.QGenericArgument(str, str)
Supported signatures:
PySide2.QtCore.QGenericArgument(PySide2.QtCore.QGenericArgument)
PySide2.QtCore.QGenericArgument(bytes = nullptr, void = nullptr)
所以看来我必须在这里使用指针,但不知道该怎么做。此外,我还没有找到 PySide2 的任何 invokeMethod 示例。
任何想法?
解决方案
推荐阅读
- sed - SED 替换包含 CR LF 的字符串
- c - 如何从另一个程序中同时启动两个 C 程序
- python - 如何打印单位矩阵的行
- python - 当特定文本出现在游戏聊天框中时发送击键的 Python 脚本
- reactjs - React Hooks 似乎没有从 API 设置数据
- javascript - GET 请求的响应体为空
- android - 首次启动时卡在启动画面,但如果我们不终止应用程序并再次启动应用程序,则应用程序可以正常工作。(反应原生)Android
- c - 我尝试编辑 .dat 文件,但它不起作用
- vb.net - 如何使用 Visual Studio 2008 在 VB 中获取新网站作为项目
- shell - Jenkinsfile:如何修改管道jenkins中传递的字符串参数