According to the first law of thermodynamics any thermodynamic process whatsoever, $$dU=\bar{d}Q-\bar{d}W_{by}$$ Moreover, is we also have $$dU=TdS-PdV$$ for any process of a system that does only P-V work provided the state functions $T,P,S$ are well defined. Now, according to several answers I've seen on this site, for any process( quasistatic or otherwise), we have $dW_{by}=P_{ext}dV$ and in the special case where the process is also quasistatic, $P_{ext}=P$ and thus $dW_{by}=PdV$. Does this, along with the first law and fundmental thermodynamic relation, imply that $$\bar{d}Q=TdS\implies Q=\int TdS$$ for any quasistatic process, reversible or otherwise? I can't find a fault in my reasoning, yet Clausius' theorem states that for an irreversible change, we have $dS>dQ/T$. Is this not a contradiction? I have a feeling that this has something to do with the fact that $T$ in the fundamental thermodynamic relation is the temperature of the system in one case and the reservoir in the other, but I am not sure about it at all. I would really appreciate if someone can help me sort this out.
Edit
I have tested the proposition for the irreversible, quasistatic isochoric heating of an ideal gas connected to a reservoir at constant temperature $T_r>T_0$. This gives $$\int_{S_0}^{S_f} TdS=C_v (T_r-T_0)=Q$$ using the expression $S=C_v\ln(T)+nR\ln(V)+C$ for an ideal gas.
The proposition appears to hold for this special case at least. I believe the expression is, in fact, true in general, because a quasistatic process can be irreversible only if there is heat transfer at a finite temperature gradient. In such a case, however, we may carry out the same change by transferring the same amount of heat at each step but reversibly (using reservoirs at slightly higher temperatures than the instantaneous temperature of the system). Then we have $$dQ=TdS$$ by Clausius' theorem, where $T$ is the common instantaneous temperature of the system and the reservoir. Clearly, however, $TdS$ here equals that in the irreversible process because each step is b/w the same two equilibrium states and at the same temperature. Does this reasoning not work?