To simulate preheating and postweld heat treatment of Q345 steel pipe welding, the finite element model was established. The welding process was simulated by method of the ANSYS element birth and death technique. In this paper, to obtain the distribution of the temperature field and stress field in different situations, preheating processes with two different values of temperature and postweld heat treatment process were simulated respectively. The results show that preheating can homogenize residual stress distribution of the weldment and decrease the residual stress. The heat treatment reduces the residual stress in inner and outer walls by 24% and 70% respectively and the stress distribution is more even and stress concentration is reduced.