The nucleation and growth of CdS nanoparticles within a polymer matrix was followed by in-situ synchrotron X-ray diffraction. The nanoparticles form by effect of the thermolysis of thiolate precursors at temperatures between 200 and 300 Celsius degrees. Above 240 Celsius degrees the precursor decomposition is complete and CdS nanoparticles grow in the polymer matrix forming a nanocomposite with interesting optical properties. The nanoparticle structural properties (size and crystal structure) depend on the annealing temperature.(abridged version)