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. Using setContextProperty with other qml files
Forum Updated to NodeBB v4.3 + New Features

Using setContextProperty with other qml files

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 2 Posters 482 Views
  • 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.
  • W Offline
    W Offline
    w.tkm
    wrote on last edited by
    #1

    Hellow.
    I want to use setContextProperty with other qml files.

    #ifdef ACTIVE
        appEngine.rootContext()->setContextProperty("ACTIVE", QVariant(true));
    #else
        appEngine.rootContext()->setContextProperty("ACTIVE", QVariant(false));
    #endif
        appEngine.load(QUrl("qrc:/qml/main.qml"));
    

    "ACTIVE" can use in main.qml.
    I want to use this in sub.qml, how do I do it?

    KroMignonK 1 Reply Last reply
    0
    • W w.tkm

      @KroMignon
      I use QQuickWidget.
      I absolutely need to use QQuickWidget.
      I want to use ACTIVE in the onClick of the button in it

      But, I got Error
      [ReferenceError: ACTIVE is not defined]

      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by
      #4

      @w-tkm said in Using setContextProperty with other qml files:

      I use QQuickWidget.
      I absolutely need to use QQuickWidget.

      QQuickWidget *view = new QQuickWidget;
      view->rootContext()->setContextProperty("ACTIVE", QVariant(false));
      view->setSource(QUrl::fromLocalFile("myqmlfile.qml"));
      view->show();
      

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      W 1 Reply Last reply
      0
      • W w.tkm

        Hellow.
        I want to use setContextProperty with other qml files.

        #ifdef ACTIVE
            appEngine.rootContext()->setContextProperty("ACTIVE", QVariant(true));
        #else
            appEngine.rootContext()->setContextProperty("ACTIVE", QVariant(false));
        #endif
            appEngine.load(QUrl("qrc:/qml/main.qml"));
        

        "ACTIVE" can use in main.qml.
        I want to use this in sub.qml, how do I do it?

        KroMignonK Offline
        KroMignonK Offline
        KroMignon
        wrote on last edited by KroMignon
        #2

        @w-tkm said in Using setContextProperty with other qml files:

        "ACTIVE" can use in main.qml.

        Why do you mean ACTIVE is only usable by main.qml?

        ACTIVE is for all items in rootContext() available. Not only main.qml.

        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

        W 1 Reply Last reply
        0
        • KroMignonK KroMignon

          @w-tkm said in Using setContextProperty with other qml files:

          "ACTIVE" can use in main.qml.

          Why do you mean ACTIVE is only usable by main.qml?

          ACTIVE is for all items in rootContext() available. Not only main.qml.

          W Offline
          W Offline
          w.tkm
          wrote on last edited by w.tkm
          #3

          @KroMignon
          I use QQuickWidget.
          I absolutely need to use QQuickWidget.
          I want to use ACTIVE in the onClick of the button in it

          But, I got Error
          [ReferenceError: ACTIVE is not defined]

          KroMignonK 1 Reply Last reply
          0
          • W w.tkm

            @KroMignon
            I use QQuickWidget.
            I absolutely need to use QQuickWidget.
            I want to use ACTIVE in the onClick of the button in it

            But, I got Error
            [ReferenceError: ACTIVE is not defined]

            KroMignonK Offline
            KroMignonK Offline
            KroMignon
            wrote on last edited by
            #4

            @w-tkm said in Using setContextProperty with other qml files:

            I use QQuickWidget.
            I absolutely need to use QQuickWidget.

            QQuickWidget *view = new QQuickWidget;
            view->rootContext()->setContextProperty("ACTIVE", QVariant(false));
            view->setSource(QUrl::fromLocalFile("myqmlfile.qml"));
            view->show();
            

            It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

            W 1 Reply Last reply
            0
            • KroMignonK KroMignon

              @w-tkm said in Using setContextProperty with other qml files:

              I use QQuickWidget.
              I absolutely need to use QQuickWidget.

              QQuickWidget *view = new QQuickWidget;
              view->rootContext()->setContextProperty("ACTIVE", QVariant(false));
              view->setSource(QUrl::fromLocalFile("myqmlfile.qml"));
              view->show();
              
              W Offline
              W Offline
              w.tkm
              wrote on last edited by
              #5

              @KroMignon
              OK, It can do it.
              Thanks!

              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