Having vector data without topology errors is important for further analysis, as these errors may lead to incorrect results.
This recipe shows you how to use the built-in GRASS tools to fix various topology errors in vector layers.
QGIS has very good integration with GRASS GIS; there is a GRASS plugin that provides access to the GRASS GIS database and functionality. GRASS algorithms are also available from the Processing plugin. The latter is simpler because you don't need to bother with setting up GRASS locations and mapsets and importing and exporting data.
To follow this recipe, load the nonbreak.shp, dangles.shp, and nosnap.shp layers from the sample data. Additionally, make sure that the Processing plugin is enabled in Plugin Manager.
The following steps show you how to fix various topology errors with the GRASS v.clean toolset using the Processing toolbox:
First, we will learn how to remove dangling lines. Dangling lines are lines that have no connection with other lines on one or either end nodes:

To remove them, perform the following steps:
dangling layer.
Cleaned layer contains cleaned geometries (shown in green) and the Errors layer contains dangles that were removed (shown in red):
Another topology issue is missed line breaks in the intersection nodes. To add break at intersections, perform the following steps:
nobreaks layer.Another very common topology issue is undershots, which happen when the line feature is not connected with another one at the intersection point and overshoots, which happens when the line ends beyond another line instead of connecting to it. Such errors often appear after inaccurate digitizing. To fix them, perform the following steps:
nosnap layer.Cleaned layer contains features with fixed errors and the Errors layer contains original invalid features.The rmdangle tool simply sequentially removes all dangling lines with length less than the given threshold. If the threshold is less than 0, then all dangles will be removed.
The break tool breaks lines at intersections, so all lines will have a common node. This tool does not need a threshold value to be specified.
The snap tool tries to snap vertices to another one within the given threshold, if no appropriate vertices are found, then no snapping is done. It is worth mentioning that large threshold values may break the topology of polygonal features.
If you need more control over the topology cleaning process, try to use v.clean.advanced from the Processing Toolbox menu or consider using the GRASS plugin.
Also, there are other ways to clean vector topology, for example, using the lwgeom functions or external tools such as prepair and pprepair. Both tools are available as Processing plugins, and they can be installed via Plugin Manager.