En esta página

Bloque «case» no vacío sin cerrar

qmllint denomina esta categoría de advertencia « [unterminated-case] ».

Bloque «case» no vacío sin cerrar

¿Qué ha ocurrido?

Un bloque «case» en una instrucción «switch» no estaba vacío, pero no se cerraba con una instrucción «break», «return» o «throw». Tampoco había ningún comentario de «fallthrough» opcional.

¿Por qué es un problema?

La lógica de «fallthrough» en las sentencias «switch» puede resultar confusa o pasar desapercibida. Si es intencionada, debe marcarse explícitamente con un comentario como «// fallthrough». Si no es intencionada, la advertencia indica que se ha olvidado incluir una instrucción de terminación.

Ejemplo

switch (state) {
case Main.State.Reset:
    clearState()                    // <--- "Unterminated non-empty case block"
case Main.State.Invalid:
    asyncInitState()
    return false
case Main.State.Initializing:
    // wait for initialization to complete
    return false
case Main.State.Ready:
    res = lookup(query)
    log(res.stats)
    saveToDisk(res.data)            // <--- "Unterminated non-empty case block"
default:
    throw new InvalidStateException("Unknown state")
}

Para solucionar esta advertencia, añade las sentencias de finalización que falten o añade comentarios explícitos que permitan la lógica de «fallthrough»:

switch (state) {
case Main.State.Reset:
    clearState()
    // fallthrough                   // <--- add fallthrough comment
case Main.State.Invalid:
    asyncInitState()
    return false
case Main.State.Initializing:
    // wait for initialization to complete
    return false
case Main.State.Ready:
    res = lookup(query)
    log(res.stats)
    saveToDisk(res.data)
    return true                     // <--- add forgotten terminating statement
default:
    throw new InvalidStateException("Unknown state")
}

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.