Congratulations to our 2022 Qt Champions!

QVariant::value returns empty while it has data.

  • I have a type which I've already registered:


    I've filled it with a pointer of my class but when getting its value this way:

    auto* instance = myVariant.value<MyType*>();

    it returns nullptr.
    I went through qt source code and it seems that it fails on type casting but my types are the same within the same module and library.

    What should I do you experts?

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Show the exact code you are using to load your custom custom class pointer in that QVariant.

    Even better, provide a minimal compilable example that shows your issue.

Log in to reply