Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Difference between setContextProperty and Qml registertype.
Forum Updated to NodeBB v4.3 + New Features

Difference between setContextProperty and Qml registertype.

Scheduled Pinned Locked Moved Unsolved General and Desktop
qmlc++
2 Posts 2 Posters 1.2k 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.
  • M Offline
    M Offline
    Mathan M
    wrote on last edited by
    #1

    Hi,

    I created an UserAccessCtlr .cpp/UserAccessCtlr .h, which has methods. This method has to call from main.qml.
    I had used to QQmlContext in the main.cpp to link the .cpp/.h files. Is it the right way, since I saw in sample, qmlRegistType.

    Option 1:
    qmlRegisterType<MapQuickView>("Esri.QTQCPPXMLIntegrationV1", 1, 0, "MapView");

    Option 2:
    QQmlContext *context = appEngine.rootContext();
    UserAccessCtlr *useraccessctlr = new UserAccessCtlr();
    context->setContextProperty("useraccessctlr",useraccessctlr);

    Query:
    What is the difference and which one i have to use it?

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

      Hi,

      Option 1 makes your type known to the QML engine and then you can instantiate new objects from that type directly in your QML code.

      Option 2 "adds" an object to the context that you can use from your QML code.

      Which one to use depends on what you want to do with that object.

      Hope it helps.

      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
      1

      • Login

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