[proofplan]
We first record that multiplication by the coordinate function and differentiation preserve the [Schwartz space](/page/Schwartz%20Space), so both compositions $QP$ and $PQ$ are defined on the same domain $\mathcal{S}(\mathbb{R})$. Then we compute the two compositions pointwise. The product rule produces one extra $\psi$ term in $P(Q\psi)$, and the terms involving $x\psi'$ cancel in the commutator.
[/proofplan]
[step:Verify that the two compositions are defined on $\mathcal{S}(\mathbb{R})$]
Let $\psi \in \mathcal{S}(\mathbb{R})$. For integers $m,k \geq 0$, define the Schwartz seminorm
\begin{align*}
\rho_{m,k}(\varphi) := \sup_{x \in \mathbb{R}} |x^m \varphi^{(k)}(x)|
\end{align*}
for every smooth function $\varphi:\mathbb{R}\to\mathbb{C}$ for which the supremum is finite.
Since $\psi \in \mathcal{S}(\mathbb{R})$, every seminorm $\rho_{m,k}(\psi)$ is finite. The derivative $\psi':\mathbb{R}\to\mathbb{C}$ satisfies
\begin{align*}
\rho_{m,k}(\psi') = \rho_{m,k+1}(\psi) < \infty
\end{align*}
for all $m,k \geq 0$, so $\psi' \in \mathcal{S}(\mathbb{R})$. Multiplication by the scalar $-i\hbar$ preserves membership in $\mathcal{S}(\mathbb{R})$, hence $P\psi \in \mathcal{S}(\mathbb{R})$.
For the position operator, define $\varphi:\mathbb{R}\to\mathbb{C}$ by $\varphi(x)=x\psi(x)$. If $k=0$, then
\begin{align*}
\rho_{m,0}(\varphi)=\sup_{x\in\mathbb{R}} |x^{m+1}\psi(x)|=\rho_{m+1,0}(\psi)<\infty.
\end{align*}
If $k\geq 1$, the product rule gives
\begin{align*}
\varphi^{(k)}(x)=x\psi^{(k)}(x)+k\psi^{(k-1)}(x)
\end{align*}
for every $x\in\mathbb{R}$. Therefore
\begin{align*}
\rho_{m,k}(\varphi)\leq \rho_{m+1,k}(\psi)+k\rho_{m,k-1}(\psi)<\infty.
\end{align*}
Thus $Q\psi\in\mathcal{S}(\mathbb{R})$. Consequently $QP\psi$ and $PQ\psi$ are both well-defined elements of $\mathcal{S}(\mathbb{R})$.
[guided]
The commutator $QP-PQ$ only makes sense on vectors for which both compositions are defined. Here the chosen domain is $\mathcal{S}(\mathbb{R})$, so we must check that applying $Q$ or $P$ keeps us inside $\mathcal{S}(\mathbb{R})$.
For integers $m,k\geq 0$, define
\begin{align*}
\rho_{m,k}(\varphi):=\sup_{x\in\mathbb{R}} |x^m\varphi^{(k)}(x)|
\end{align*}
for every smooth function $\varphi:\mathbb{R}\to\mathbb{C}$ for which this supremum is finite. A function lies in $\mathcal{S}(\mathbb{R})$ exactly when all these seminorms are finite.
Since $\psi\in\mathcal{S}(\mathbb{R})$, all quantities $\rho_{m,k}(\psi)$ are finite. Differentiation shifts the derivative index:
\begin{align*}
\rho_{m,k}(\psi')=\sup_{x\in\mathbb{R}} |x^m\psi^{(k+1)}(x)|=\rho_{m,k+1}(\psi)<\infty.
\end{align*}
Thus $\psi'\in\mathcal{S}(\mathbb{R})$. Multiplying by the fixed scalar $-i\hbar$ does not affect rapid decay or smoothness, so $P\psi=-i\hbar\psi'$ also belongs to $\mathcal{S}(\mathbb{R})$.
Now consider $Q\psi$. Define $\varphi:\mathbb{R}\to\mathbb{C}$ by $\varphi(x)=x\psi(x)$. For $k=0$,
\begin{align*}
\rho_{m,0}(\varphi)=\sup_{x\in\mathbb{R}} |x^m x\psi(x)|=\rho_{m+1,0}(\psi)<\infty.
\end{align*}
For $k\geq 1$, differentiating $x\psi(x)$ gives one term where the derivative lands on $\psi$ and one term where a single derivative lands on $x$:
\begin{align*}
\varphi^{(k)}(x)=x\psi^{(k)}(x)+k\psi^{(k-1)}(x).
\end{align*}
Therefore
\begin{align*}
\rho_{m,k}(\varphi)\leq \rho_{m+1,k}(\psi)+k\rho_{m,k-1}(\psi)<\infty.
\end{align*}
So $Q\psi\in\mathcal{S}(\mathbb{R})$. Since both $Q$ and $P$ map $\mathcal{S}(\mathbb{R})$ into itself, the compositions $QP\psi$ and $PQ\psi$ are defined for every $\psi\in\mathcal{S}(\mathbb{R})$.
[/guided]
[/step]
[step:Compute $QP\psi$ pointwise]
Let $x\in\mathbb{R}$. By the definitions of $Q$ and $P$,
\begin{align*}
(QP\psi)(x)=Q(P\psi)(x)=x(P\psi)(x)=x(-i\hbar\psi'(x)).
\end{align*}
Hence
\begin{align*}
(QP\psi)(x)=-i\hbar x\psi'(x).
\end{align*}
[/step]
[step:Compute $PQ\psi$ using the product rule]
Let $x\in\mathbb{R}$. By the definitions of $P$ and $Q$,
\begin{align*}
(PQ\psi)(x)=P(Q\psi)(x)=-i\hbar\frac{d}{dx}(x\psi(x)).
\end{align*}
Applying the product rule to the smooth functions $x\mapsto x$ and $\psi:\mathbb{R}\to\mathbb{C}$ gives
\begin{align*}
\frac{d}{dx}(x\psi(x))=\psi(x)+x\psi'(x).
\end{align*}
Therefore
\begin{align*}
(PQ\psi)(x)=-i\hbar\psi(x)-i\hbar x\psi'(x).
\end{align*}
[/step]
[step:Subtract the two compositions to obtain the commutator]
For every $x\in\mathbb{R}$, subtracting the formula for $PQ\psi$ from the formula for $QP\psi$ gives
\begin{align*}
((QP-PQ)\psi)(x)=(-i\hbar x\psi'(x))-(-i\hbar\psi(x)-i\hbar x\psi'(x)).
\end{align*}
After cancellation of the two terms involving $x\psi'(x)$, this becomes
\begin{align*}
((QP-PQ)\psi)(x)=i\hbar\psi(x).
\end{align*}
Since this equality holds for every $x\in\mathbb{R}$, we have
\begin{align*}
[Q,P]\psi=(QP-PQ)\psi=i\hbar\psi.
\end{align*}
Because $\psi\in\mathcal{S}(\mathbb{R})$ was arbitrary, the identity holds on the common invariant domain $\mathcal{S}(\mathbb{R})$.
[/step]