C. John ("Jack") Collins--OT professor and department chairman at Covenant Theological Seminary--once preached a sermon on Ecclesiastes 3 and the problem of pain after the loss of a child. I recommend reading it.
The sermon is helpful for thinking about God and pain in a fallen world, and is also helpful in thinking about how to read the book of Ecclesiastes.