You do have to start building after getting the quest in order for the happiness to register when the building is complete (even though you don't get the happiness until it finishes, i.e. well after the quest started). I had to demolish a half-built cartographer because I happened to have started it a couple of hours before being told to gain happiness :-(
N.B. the easiest way to gain happiness is to build and sell Stone Age monuments (happiness 72, cost 19 gold +19 supplies) repeatedly - the quest registers the gain of happiness after 5 secobds when they complete and then ignores the loss when you delete them :O