It's important to be alert to mate threats. One way to find them is by looking at any pieces already attacking squares adjacent to the king. Here White’s knight attacks g7, and the square is protected only by Black’s king. If White were to add an attack on that square by his queen, he would threaten mate, so naturally he looks at Qg4. The move not only creates a mate threat but also moves the queen behind the knight on f5, creating the kernel of a discovery—the two queens with a knight between them. How would Black respond to the mate threat? He can play g7-g6; but even so, Nh6, while not threatening mate, then gives check and unmasks the capture QxQ. Again we see that the key is to create the kernel while also creating a side threat that busies your opponent.