In Catholic school we weren’t taught that Solomon wrote Ecclesiastes. The author was just referred to as Qoholeth, or The Teacher. There were several reasons why they didn’t attribute it to Solomon, including some of the language used, but just from the text itself, it suggests that he had been king over Israel but wasn’t any longer, while Solomon was always king. Him being a son of David could just mean a descendant of David.