As a typical quantum computing algorithm, quantum annealing is widely used in the optimization of glass-like problems to find the best solution. However, the optimization problems in constrained complex systems usually involve topological structures, and the performance of the quantum annealing algorithm is still largely unknown. Here, we take an Ising system as a typical example with local constraints accompanied by intrinsic topological properties that can be implemented on quantum computing platforms such as the D-wave machine, and study the effectiveness of the quantum annealing algorithm in its optimization and compare it with that of the thermal annealing. We find that although conventional quantum annealing is difficult for the optimization of constrained topological problems, a generalized algorithm --- the sweeping quantum annealing method --- can be designed and solve the problem with better efficiency than both conventional quantum and thermal annealing algorithms. The sweeping quantum annealing algorithm, therefore, opens up a promising avenue for quantum computing of constrained problems and can be readily employed on the optimizations in quantum material design, engineering, and even social sciences.