$Q$, the set of all rationals is not connected as there exists a partition of open sets $Q=(Q\cap (-\infty, \sqrt 2))\cup (Q\cap (\sqrt 2, \infty))$.
The following proof shows however that $Q$ is connected:
Suppose that $U\subset Q$ is any clopen set. It suffices to show that $U\in\{\emptyset, Q\}$.
$U\subset Q$ is open so there exists open set $V\subset R$ such that $U=V\cap Q$.
$U\subset Q$ is closed so there exists a closed set $V_1\subset R$ such that $U=V_1\cap Q$.
$\emptyset =U-U=(V-V_1)\bigcap Q$. By density of $Q$, since $V-V_1$ is open in $R$, it must be the emptyset. It follows that $V=V_1$.
$V$ is clopen in $R$. Since $R$ is connected, $V=\emptyset$ or $V=R$. It follows that $U\in \{\emptyset, Q\}$. So $Q$ is connected.
Using the same proof, $R\setminus Q$ is connected.
What is wrong in the above proof? Thanks.
$V-V_1=\emptyset$ does not imply $V=V_1$. What if $V\subseteq V_1$?
With your example at the start, we could have $V=(-\infty,\sqrt{2})$ and $V_1:=(-\infty,\sqrt{2}]$.