Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [Solved] viewer.engine()->rootContext()->setContextProperty(...) - main.cpp:41: error: C2248: 'QVariant::QVariant' : cannot access private member dec

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

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 5.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LakshmiSaripella
    wrote on last edited by
    #1

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

    using
    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • L Offline
        L Offline
        LakshmiSaripella
        wrote on last edited by
        #3

        Thanks. Its working and saved my day.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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 :)

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved