"I have seen another evil under the sun, and it weighs heavily on men: God gives a man wealth, possessions and honor, so that he lacks nothing his heart desires, but God does not enable him to enjoy them, and a stranger enjoys them instead. This is meaningless, a grievous evil." NIV translation
In chapter five, we saw Solomon's conclusion on the hoarding of wealth instead of sharing with those in need. He continues with the theme of possessions as he speaks of the man that has it all but does not have the ability to enjoy it. This speaks of contentment which is basically celebrating what God has given us. We often see cases of people who spend all of their time acquiring possessions or chasing recognition for their activities and yet die at an early age. God has numbered the days of each of us and we can use them as we want but we do not know how many we have. It is meaningless to store up things for a day in the future that you might not even have.
"A man may have a hundred children and live many years; yet no matter how long he lives, if he cannot enjoy his prosperity and does not receive proper burial, I say that a stillborn child is better off than he." NIV translation
Even if God grants us many days, what good are the days if we do not have contentment? If we do not slow down to enjoy the relationships that God has provided, Solomon says that we would be better off to have never lived.
Many people today pass away and leave nobody that misses them or even knows they are gone. This is sad and they are no better off than a child that never had the chance to live.
"It comes without meaning, it departs in darkness, and in darkness its name is shrouded. Though it never saw the sun or knew anything, it has more rest than does that man - even if he lives a thousand years twice over but fails to enjoy his prosperity. Do not all go to the same place?" NIV translation
The stillborn child does not have to face the struggles of this world but instead goes to be with Jesus for eternity. That baby is better off than the man who lives a long life without happiness and contentment. That is what Paul was talking about when he said that it would be gain for him to die and to go to be with the Lord (see Philippians 1:21).