Here's a way to use connectedness, really amounting to using the intermediate value theorem.
If $f(\mathbb{Q})\subseteq \mathbb R\setminus\mathbb Q$ and $f(\mathbb R\setminus \mathbb Q)\subseteq\mathbb Q$, then $f(0)\neq f(\sqrt 2)$. Because intervals are connected in $\mathbb R$ and $f$ is continuous, $f[0,\sqrt 2]$ is connected. Because connected subsets of $\mathbb R$ are intervals, $f[0,\sqrt 2]$ contains the interval $\left[\min\{f(0),f(\sqrt 2)\},\max\{f(0),f(\sqrt 2)\}\right]$. The set of irrational numbers in this interval is uncountable, yet contained in the countable set $f(\mathbb Q)$, a contradiction.
A slightly briefer outline: The hypothesis implies that $f$ is nonconstant with range contained in the countable set $\mathbb Q\cup f(\mathbb Q)$, whereas the intermediate value theorem and uncountability of $\mathbb R$ imply that a nonconstant continuous function $f:\mathbb R\to\mathbb R$ has uncountable range.