Massive copypasta from upstream qt