If $A$ is invertible, then the $QR$-factorization is unique if we require that the diagonal elements of $R$ are positive. Let $A=QR$ be a $QR$-decomposition. Then the wikipedia  article regarding $QR$ decomposition states that 

If $A$ is invertible, then the factorization is unique if we require
  that the diagonal elements of $R$ are positive.

I don't understand the relation of diagonal elements being positive to uniqueness. Can someone explain what happens if they are non-negative, say some of them are zero, and what happens if they are all real. 
 A: To convince yourself that
when multiplying two matrices, if scale k-th column of the matrix on the left by $\alpha$ and the k-th row of the matrix on the right by $1/\alpha$ then the product does not change.
So we can always multiply the column of $Q$ by $-1$ and the corresponding row of $R$ also by $-1$, the we have another QR factorization. So requiring the diagonal to be positive prevents this ambiguity.
By the way, the ambiguity actually comes from taking square roots when calculating the columns of Q. Depending on the sign of the square root, we can end up with either positive value or a negative value on the diagonal of $R$.
Also, if $A$ is singular, then one or more of the diagonal entries of $R$ would be zero. In this case, scaling by $-1$ the column of $Q$ that goes with the diagonal value of zero does not change the diagonal value of $R$. This is why we need $A$ to be nonsingular.
A: 
Lemma 1 The inverse of an upper triangular matrix is an upper triangular matrix.
Lemma 2 The upper triangular matrix whose is orthogonal must be a diagonal matrix with the number $1$ or $-1$.

These can contribute to the uniqueness of the real matrix. However the complex case may related to the complex number, so I don not think there is the uniqueness about complex case.

Next, I prove the uniqueness.
Let $A$ be an nonsingular real matrix. And $A=Q_1R_1=Q_2R_2$($Q_1,Q_2$ is orthogonal and $R_1,R_2$ is upper triangular matrix with the positive diagonal)
Then we have $P=Q_2^{-1}Q_1=R_2R_1^{-1}$. From the left side, we can get $P$ is orthogonal. From the right side, we can get $P$ is upper triangular matrix(Lemma 1). So $P$ is a upper triangular matrix whose is orthogonal. Then $P$ is a diagonal matrix with the number $1$ or $-1$(Lemma 2).
Because $R_1,R_2$ is upper triangular matrix with the positive diagonal, the number of $P$ is also positive. So $P=I$.
That is to say $Q_1=Q_2,R_1=R_2$.

The uniqueness of nonsingular of real matrix is proved.
