擅长:python、mysql、java
<p>它们添加第三个参数<code>type=</code>来设置结果的类型。所以您可以使用<code>type=bool</code>并获得Python<code>True/False</code>,而不是字符串<code>"true"/"false"</code></p>
<pre><code>a = self._settings.value("test_value", True, type=bool)
print('a:', type(a), a)
b = self._settings.value("test_value", True)
print('b:', type(b), b)
</code></pre>
<p>结果</p>
^{pr2}$
<hr/>
<p>在谷歌找到:<a href="https://riverbankcomputing.com/pipermail/pyqt/2011-January/029032.html" rel="noreferrer">https://riverbankcomputing.com/pipermail/pyqt/2011-January/029032.html</a></p>
<blockquote>
<ul>
<li>Added the optional <strong>type</strong> keyword argument to QSettings.value() to allow
the type of the returned value to be specified.</li>
</ul>
</blockquote>