Here, the book of Ecclesiastes takes an encouraging turn. Solomon begins to lose his sense of hopelessness, and we see the first positive reference to God in the book. In chapter 1, God appeared but not in a very good sense. The positive turn continues throughout the book.
Solomon does not completely stop writing despairing things. However, they are despairing thoughts on individual, specific areas of life, not his overall conclusion. In this verse, there is a positive conclusion.
Before this, he says that all of his labor was nothing but frustration, but now he sings a different tune. So far, he has painted a dismal picture of life, but now a change begins as he has presented the worse part of his treatise.
God intends that we receive enjoyment, fulfillment, good education—positive things—from the work that we do. Solomon rightly concludes that this is from the hand of God. Certainly, God intends that we receive good things, but remember, Solomon makes his judgments based upon things that are "under the sun," that is, apart from God.
He is beginning to argue that life begins to flesh out, have meaning, fulfillment, the right kind of pleasure, and balance when a person is connected to God. In other words, what Solomon did earlier—all of the works he entered into, his seeking after pleasure, his observations of the natural cycles of the earth, his search for wisdom—are described from the perspective of a person disconnected from God.
John W. Ritenbaugh
Ecclesiastes and the Feast of Tabernacles (Part 2)