From FIDE Laws of Chess, article 5.2b:
The game is drawn when a position has arisen in which neither player can checkmate the opponent’s king with any series of legal moves. The game is said to end in a ‘dead position’. This immediately ends the game, provided that the move producing the position was legal. (See Article 9.6).
In your first example, as soon as White plays Qh2+, the statement "a position has arisen in which neither player can checkmate the opponent’s king with any series of legal moves" becomes true. As the rule says, this immediately ends the game with a draw. This happened on White's move and it immediately ends the game, so there is no time for Black's flag to fall.
The same happens in your second example. As soon as a dead position arises, it is a draw.
The position does not need to be dead for a fallen flag to result in a draw. Article 6.9 makes it even clearer: even if a flag has fallen, a dead position is a drawsays:
Except where one of the Articles: 5.1.a, 5.1.b, 5.2.a, 5.2.b, 5.2.c applies, if a player does not complete the prescribed number of moves in the allotted time, the game is lost by the player. However, the game is drawn, if the position is such that the opponent cannot checkmate the player’s king by any possible series of legal moves.
So if Black's flag falls and there is no legal sequence of moves that results in Black's king being checkmated, it is a draw. For example, if Black has an extra queen in your first example, and Black's flag falls after this move
[FEN "8/8/8/5q2/8/8/Q7/K6k w - - 0 1"]
1. Qh2+
then it is still a draw, because there is no legal sequence of moves can result in Black's king being checkmated.