Also in your example, it looks like your passing the function itself into qmlRegisterSingleton You only posted a small snippet though.
As of what i read through the docs, i found that QQmlEngine Class | Qt QML 5.15.12 tells me i have to allocate the singleton object before the engine to make sure it outlives engine but in this scenario, I believe there is no way to allocate it before the engine. So how do i go around this issue. When i just tried that way without somehow allocating before engine, I get The registered singleton has already been deleted. Ensure that it outlives the engine.