这个警告是在哪里发出的 'QApplication: invalid style override passed, ignoring it.'?
Where is this warning being raised 'QApplication: invalid style override passed, ignoring it.'?
我的代码发出警告(不确定这是否真的是警告)
QApplication: invalid style override passed, ignoring it.
但没有别的。它没有告诉我代码的哪一部分引发了它。
我怎么知道我的代码的哪一部分触发了这个警告?
How can I know which part of my code is triggering this warning?
从调用 GUI 的代码部分开始。鉴于 OP 似乎是一位科学家,我会大胆猜测 matplotlib
参与其中。我可以用
重现消息
import matplotlib.pyplot as plt
plt.plot([1, 2])
使用以下软件包版本(来自 conda list
):
matplotlib 2.2.2 py36h0e671d2_1 defaults
pyqt 5.9.2 py36h751905a_0 defaults
qt 5.9.4 h4e5bff0_0 defaults
[编辑]:我刚刚为我自己的 C++ 代码找到了更好的解决方案。它仍然只是一个 "workaround," 但警告消失了。在 main()
函数的最顶部添加一行,如下所示:
int main(int argc, char *argv[])
{
qputenv("QT_STYLE_OVERRIDE",0);
...
这将取消设置导致警告的环境变量。
[旧答案]:
Error message:
QApplication: invalid style override passed, ignoring it.
To remove this error message:
In Qt Creator (ver 4.4.1)
Select "Projects" (wrench icon on left edge)
Under "Build & Run" (left pane)
Select "Run"
Under "Run Settings" (right pane)
Under "Run Environment"
Select "Details" (drop down list)
Scroll down to "QT_STYLE_OVERRIDE"
Click it to highlight it
Then click "Unset" button (right side)
Click "Details" to close the list
Now when you run the application you shouldn't see this error message.
这个问题来自qt 5.9.2和pyqt 5.9.2。
Anaconda 团队知道这个问题,但他们忽略了它,因为它主要来自 qt。
我收到 anaconda-navigator (Anaconda3-5.2.0-Linux-x86_64) 的错误,这导致我的 Spyder (v3.2.8) IDE for Python 3.6 变得不可见。降级qt和pyqt解决了这个问题。
要降级,请在控制台中输入:
conda install pyqt=5.6
注意:如果您的 conda 未更新,您需要在 运行 执行上述命令之前更新 conda。更新 conda 运行:
conda update -n base conda
希望这也能解决您的问题。
在 Ubuntu 18.04,我安装了 anaconda。
$ anaconda-navigator
QApplication: invalid style override passed, ignoring it.
当来自 anaconda-navigator 的 运行 spyder 时:
/home/username/.anaconda/navigator/scripts/spyder.sh: line 3: 31873 Segmentation fault (core dumped) spyder >
/home/username/.anaconda/navigator/scripts/spyder-out-1.txt 2>
/home/username/.anaconda/navigator/scripts/spyder-err-1.txt
当运行 spyder 从命令行:
/home/username/.anaconda/navigator/scripts/spyder.sh: line 3: 31873 Segmentation fault (core dumped) spyder >
/home/username/.anaconda/navigator/scripts/spyder-out-1.txt 2>
/home/username/.anaconda/navigator/scripts/spyder-err-1.txt
这解决了我的问题:
$ conda install pyqt=5.6
非常感谢Narnia_Optimus
此消息的原因是环境变量 QT_STYLE_OVERRIDE 在您的系统上设置为 Qt 安装不支持的值。你可以用
检查这个
sh-prompt> set | grep QT
要修复此警告,您可以更改 /etc/profile
或 $HOME/.bashrc
中的变量,或者 - 如果只有一个程序受到影响 - 使用
启动程序
QT_STYLE_OVERRIDE="" program
在您的程序代码中使用 qputenv
取消设置变量(如 Harvey 建议的那样)将产生副作用,即您的应用程序会忽略样式首选项,即使在以下系统上也是如此支持一下。
我的代码发出警告(不确定这是否真的是警告)
QApplication: invalid style override passed, ignoring it.
但没有别的。它没有告诉我代码的哪一部分引发了它。
我怎么知道我的代码的哪一部分触发了这个警告?
How can I know which part of my code is triggering this warning?
从调用 GUI 的代码部分开始。鉴于 OP 似乎是一位科学家,我会大胆猜测 matplotlib
参与其中。我可以用
import matplotlib.pyplot as plt
plt.plot([1, 2])
使用以下软件包版本(来自 conda list
):
matplotlib 2.2.2 py36h0e671d2_1 defaults
pyqt 5.9.2 py36h751905a_0 defaults
qt 5.9.4 h4e5bff0_0 defaults
[编辑]:我刚刚为我自己的 C++ 代码找到了更好的解决方案。它仍然只是一个 "workaround," 但警告消失了。在 main()
函数的最顶部添加一行,如下所示:
int main(int argc, char *argv[])
{
qputenv("QT_STYLE_OVERRIDE",0);
...
这将取消设置导致警告的环境变量。
[旧答案]:
Error message:
QApplication: invalid style override passed, ignoring it.
To remove this error message:
In Qt Creator (ver 4.4.1)
Select "Projects" (wrench icon on left edge)
Under "Build & Run" (left pane)
Select "Run"
Under "Run Settings" (right pane)
Under "Run Environment"
Select "Details" (drop down list)
Scroll down to "QT_STYLE_OVERRIDE"
Click it to highlight it
Then click "Unset" button (right side)
Click "Details" to close the list
Now when you run the application you shouldn't see this error message.
这个问题来自qt 5.9.2和pyqt 5.9.2。 Anaconda 团队知道这个问题,但他们忽略了它,因为它主要来自 qt。
我收到 anaconda-navigator (Anaconda3-5.2.0-Linux-x86_64) 的错误,这导致我的 Spyder (v3.2.8) IDE for Python 3.6 变得不可见。降级qt和pyqt解决了这个问题。
要降级,请在控制台中输入:
conda install pyqt=5.6
注意:如果您的 conda 未更新,您需要在 运行 执行上述命令之前更新 conda。更新 conda 运行:
conda update -n base conda
希望这也能解决您的问题。
在 Ubuntu 18.04,我安装了 anaconda。
$ anaconda-navigator
QApplication: invalid style override passed, ignoring it.
当来自 anaconda-navigator 的 运行 spyder 时:
/home/username/.anaconda/navigator/scripts/spyder.sh: line 3: 31873 Segmentation fault (core dumped) spyder >
/home/username/.anaconda/navigator/scripts/spyder-out-1.txt 2>
/home/username/.anaconda/navigator/scripts/spyder-err-1.txt
当运行 spyder 从命令行:
/home/username/.anaconda/navigator/scripts/spyder.sh: line 3: 31873 Segmentation fault (core dumped) spyder >
/home/username/.anaconda/navigator/scripts/spyder-out-1.txt 2>
/home/username/.anaconda/navigator/scripts/spyder-err-1.txt
这解决了我的问题:
$ conda install pyqt=5.6
非常感谢Narnia_Optimus
此消息的原因是环境变量 QT_STYLE_OVERRIDE 在您的系统上设置为 Qt 安装不支持的值。你可以用
检查这个 sh-prompt> set | grep QT
要修复此警告,您可以更改 /etc/profile
或 $HOME/.bashrc
中的变量,或者 - 如果只有一个程序受到影响 - 使用
QT_STYLE_OVERRIDE="" program
在您的程序代码中使用 qputenv
取消设置变量(如 Harvey 建议的那样)将产生副作用,即您的应用程序会忽略样式首选项,即使在以下系统上也是如此支持一下。