Disable specific warning in Qt Creator

  • Apparently the new version of Qt Creator checks for warnings while I'm writing the code. That's a nice feature, but I find some of the warnings more annoying than helpful. For example, one of the warnings I find most annoying is "enumeration values not handled in switch", since if I have a QMessageBox that only has 3 buttons it expects me to handle all 20 enumeration values even though I know that only 3 of those values are possible. For example I get a useless warning for the following code:

    switch(QMessageBox::warning(this, "", "Do you want to save the file before leaving?", QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel)){
    case QMessageBox::Yes:
        //Save and quit
    case QMessageBox::Cancel:
        //Don't quit
    case QMessageBox::No:

    My question is how can I disable a certain type of warning in Qt Creator?

  • I found the solution. It's in Options > C++ > Code Model > Manage..., then press the "Copy" button. Then in the Clang tab, there will be a text area. If you type -w in the text area, it disables all warnings. To keep some of the warnings enabled, see here for what to put in there.

  • Lifetime Qt Champion

    Just as a note
    if you add default case, it stops warning.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.