Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is this warning being raised 'QApplication: invalid style override passed, ignoring it.'?

My code is throwing the warning (not sure if this is actually a warning)

QApplication: invalid style override passed, ignoring it.

but nothing else. It does not tell me which part of the code is raising it.

How can I know which part of my code is triggering this warning?

like image 304
Gabriel Avatar asked Apr 12 '18 14:04

Gabriel


4 Answers

The cause for this message is that the environment variable QT_STYLE_OVERRIDE is set on your system to a value not supported by your Qt installation. You can check this with

    sh-prompt> set | grep QT

To fix this warning, you can either change the variable in /etc/profile or $HOME/.bashrc, or -if only one program is affected- start the program with

    QT_STYLE_OVERRIDE="" program

Unsetting the varible with qputenv in your program code (as Harvey suggested) will have the side effect that style preferences are ignored by your application even on systems that support it.

like image 127
cdalitz Avatar answered Nov 15 '22 15:11

cdalitz


This problem comes from qt 5.9.2 and pyqt 5.9.2. This problem is known to Anaconda team and they are ignoring it because it primarily comes from qt.

I got this error for anaconda-navigator (Anaconda3-5.2.0-Linux-x86_64) and this caused my Spyder (v3.2.8) IDE for Python 3.6 getting invisible. Downgrading qt and pyqt solved the problem.

To downgrade, type in console:

conda install pyqt=5.6

Note: In case, your conda is not updated, you need to update conda before running the above command. To update conda run:

conda update -n base conda

Hope this will solve your problem too.

like image 39
Narnia_Optimus Avatar answered Nov 15 '22 16:11

Narnia_Optimus


How can I know which part of my code is triggering this warning?

Start with the parts of your code that invoke a GUI. Given that the OP appears to be a scientist, I'll take a wild guess that matplotlib is involved. I can reproduce the message with

import matplotlib.pyplot as plt
plt.plot([1, 2])

using the following package versions (from conda list):

matplotlib                2.2.2            py36h0e671d2_1    defaults
pyqt                      5.9.2            py36h751905a_0    defaults
qt                        5.9.4                h4e5bff0_0    defaults
like image 23
drammock Avatar answered Nov 15 '22 16:11

drammock


[EDIT]: I just found a better solution for my own C++ code. It is still only a "workaround," but the warning is gone. Add one line at the very top of the main() function, like this:

int main(int argc, char *argv[])
{
    qputenv("QT_STYLE_OVERRIDE",0);
    ...

This will unset the environment variable causing the warning.

[OLD ANSWER]:

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.
like image 26
Harvey Avatar answered Nov 15 '22 17:11

Harvey