It looks like you're doing something along the lines of a present value computation, where you are trying to look at costs into the future; since currency is worth less as time goes on, those costs can be backward-extrapolated to the present day and you can see how much of a burden they are in today's dollars.
You probably remember from calculus that $\int_a^b \frac{d}{dx}f(x)\,dx = f(a)-f(b)$; this is one of the Fundamental Theorems of Calculus and basically it's what we always use to solve integrals. We apply this principle for $f(x)= q(x)e^{-r(x-t)}$, and $a=t$ and $b=T$. Recalling the product and chain rules for derivatives, this yields
\begin{align*}
\int_t^T\left[\dot q(x)e^{-r(x-t)}-q(x)re^{-r(x-t)}\right]\,dx &= q(T)e^{-r(T-t)}-q(t)e^0 \\
\int_t^T -\left[-\dot q(x)+q(x)r\right]e^{-r(x-t)}\,dx &= q(T)e^{-r(T-t)}-q(t) \\
q(t)-\int_t^T e^{-r(x-t)}\pi(K(x))\,dx &= e^{-r(T-t)}q(T) \\
\end{align*}
Adding the integral to both sides yields the given equation, except that the upper limit is $T$ instead of $\infty$.* I suspect your text is taking the limit as $T\to\infty$ (in practical terms: looking at the costs further and further into the future), in which case the $T$ in the integral does become an $\infty$, but we have to figure out what happens to the "extra" right-hand side term for large $T$. So I'm hoping the next bit of the text is devoted to that; but do let me know if I'm off base.
(* And my variable of integration is $x$ instead of $\tau$. This doesn't matter; it's just a name. Remember that when you have $\int_a^b g(x)dx$, all that matters is that you plug in $x=a$ and $x=b$ at the end, and then the $x$ has disappeared. So of course we can just as well call it $\tau$. I chose the notation that stuck closer to a calculus course than to your text so that the theory part would look more familiar.)