spin_100 said:
Also why is T treated as a constant if we start by replacing dQ by TdS?
The formula ##d'Q=TdS## does not imply that ##T## is constant.
For analogy, consider classical mechanics of a particle moving in one dimension. The infinitesimal path ##dx## during the time ##dt## is ##dx=vdt##, but it does not imply that the velocity ##v(t)## is constant. Instead, it means that ##v(t)## is defined as
$$v(t)=\frac{dx(t)}{dt}$$
which physicists write in the infinitesimal form ##dx=vdt##.
Indeed, similarly to ##v##, the ##T## can also be thought of as defined by a derivative formula. But it is not ##T=d'Q/dS## or ##T=dQ/dS##, because such things are not defined as derivatives. Instead, starting from the 1st law of thermodynamics
$$dU=TdS-PdV$$
we see that ##U## must be a function of ##S## and ##V##, because then we have the mathematical identity
$$dU(S,V)=\left( \frac{\partial U(S,V)}{\partial S} \right)_V dS +
\left( \frac{\partial U(S,V)}{\partial V} \right)_S dV$$
which is compatible with the 1st law above. The compatibility implies that ##T## can be defined as
$$T(S,V)=\left( \frac{\partial U(S,V)}{\partial S} \right)_V$$
which is a function of ##S## and ##V##, not a constant.