Try $q(x) = (x^2+1)^3$ with $n = 6$. The space of polynomials $p(x)$ such that $\int_0^1 \frac{p(x)}{q(x)} \; dx \in \mathbb Q \pi$ is infinite-dimensional. If you meant polynomials of degree $< 6$, that has dimension $4$, as the following $4$ linearly independent polynomials $p(x)$ qualify: $$ 4 x - 3, x^2, 4 x^3 - 1, x^4 + 1 $$