首页 > 解决方案 > 在 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 示例。

任何想法?

标签: pythonpyside2

解决方案


推荐阅读