Problems with Open-Source Downloads read and

[Solved] viewer.engine()->rootContext()->setContextProperty(...) - main.cpp:41: error: C2248: 'QVariant::QVariant' : cannot access private member dec

  • We are trying to pass the following object to .qml
    Brand *tmpBrand = new Brand("45678","Sprite.png","0");

    viewer.engine()->rootContext()->setContextProperty(""brand", &tmpBrand)

    We encounter error "main.cpp:41: error: C2248: 'QVariant::QVariant' : cannot access private member declared in class 'QVariant' " and unable to proceed further.

    However, the following makes us move ahead with no problem
    Brand brand;
    viewer.engine()->rootContext()->setContextProperty("brand", &brand);

    But, the object "brand" does not have required member values. We intend to update the values and use the newly create object using "Brand *tmpBrand"

    Is there any other work around to pass currently updated object to my .qml file for UI presentation.

    Any quick answer helps us in great way.

  • Lifetime Qt Champion


    Looking at the setContextProperty doc, it should rather be something like:

    Brand tmpBrand("45678", "Sprite.png", "0");
    viewer.engine()->rootContext()->setContextProperty(”brand”, QVariant::fromValue(tmpBrand));

    Otherwise you would be passing a pointer to a pointer to a Brand object.

  • Thanks. Its working and saved my day.

  • Lifetime Qt Champion

    You're welcome !

    Don't forget to update the thread's title to solved (prepending it) so other forum users will know that a solution has been found :)

Log in to reply