在 C++ 中 BoolResult 被强制转换为指针:
bool ok;
int i = QInputDialog::getInt(this, tr("QInputDialog::getInteger()"),
tr("Percentage:"), 25, 0, 100, 1, &ok);
if (ok)
integerLabel->setText(tr("%1%").arg(i));
如何在 pyQt/pythonQt 中检索“ok”布尔值?
它尝试了以下不起作用:
from PythonQt.QtGui import QInputDialog, QWidget
from PythonQt.QtCore import Qt, QTimer
from PythonQt import BoolResult
...
x = QWidget()
x.setAttribute(Qt.WA_DeleteOnClose)
ok = BoolResult()
i = QInputDialog.getInt(x, "test", "hallo", 1000, None, None, None, ok)
print("ok:", ok)
print("i:", i)
print("i:", i)
这导致
2/24/2018 17:49:42 pyTSon.PluginHost.onMenuItemEvent Error Error calling onMenuItemEvent of python plugin Auto Channel Commander: Traceback (most recent call last):
File "C:/Users/blusc/AppData/Roaming/TS3Client/plugins/pyTSon/scripts\pluginhost.py", line 663, in onMenuItemEvent
plugin.onMenuItemEvent(schid, atype, locid, selectedItemID)
File "C:/Users/blusc/AppData/Roaming/TS3Client/plugins/pyTSon/scripts\autoCommander\__init__.py", line 64, in onMenuItemEvent
i = QInputDialog.getInt(x, "test", "hallo", 1000, None, None, None, ok)
ValueError: Could not find matching overload for given arguments:
(QWidget(0x2759aa87560) , 'test', 'hallo', 1000, None, None, None, BoolResult(False))
The following slots are available:
static getInt(QWidget parent, QString title, QString label, int value, int minValue, int maxValue, int step, PythonQt.BoolResult ok, Qt::WindowFlags flags) -> int
static getInt(QWidget parent, QString title, QString label, int value, int minValue, int maxValue, int step, PythonQt.BoolResult ok) -> int
static getInt(QWidget parent, QString title, QString label, int value, int minValue, int maxValue, int step) -> int
static getInt(QWidget parent, QString title, QString label, int value, int minValue, int maxValue) -> int
static getInt(QWidget parent, QString title, QString label, int value, int minValue) -> int
static getInt(QWidget parent, QString title, QString label, int value) -> int
static getInt(QWidget parent, QString title, QString label) -> int