Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. qml dummy property
Qt 6.12 LTS is out! See what's new in the release blog

qml dummy property

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 Posters 861 Views 2 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.
  • P Offline
    P Offline
    poucz
    wrote on last edited by
    #1

    Hello,
    I'm interesting into qmlscene.
    In project I use:

    engine.rootContext()->setContextProperty("PP_IP", QVariant("192.168.100.195"));
    

    to set device IP adress.

    And in QML:

        Component.onCompleted: {
            console.log("Test from example: "+PP_IP.time) //this is for debug
           console.log("Test: "+PP_IP) //this is what I need
        }
    

    Now I want use dummy data to set PP_IP when I running qml in qmlscene.

    So I created file dummydata/PP_IP.qml
    In this file I have

    import QtQuick 2.3
    QtObject { property int time: 54321 }
    

    Like in example , OK it is working.
    But I need print variable PP_IP not PP_IP.time.
    What I have to change in "dummydata/PP_IP.qml" ??
    Thank you very much

    DiracsbracketD 1 Reply Last reply
    0
    • P poucz

      Hello,
      I'm interesting into qmlscene.
      In project I use:

      engine.rootContext()->setContextProperty("PP_IP", QVariant("192.168.100.195"));
      

      to set device IP adress.

      And in QML:

          Component.onCompleted: {
              console.log("Test from example: "+PP_IP.time) //this is for debug
             console.log("Test: "+PP_IP) //this is what I need
          }
      

      Now I want use dummy data to set PP_IP when I running qml in qmlscene.

      So I created file dummydata/PP_IP.qml
      In this file I have

      import QtQuick 2.3
      QtObject { property int time: 54321 }
      

      Like in example , OK it is working.
      But I need print variable PP_IP not PP_IP.time.
      What I have to change in "dummydata/PP_IP.qml" ??
      Thank you very much

      DiracsbracketD Offline
      DiracsbracketD Offline
      Diracsbracket
      wrote on last edited by
      #2

      @poucz said in qml dummy property:

      Component.onCompleted: {
          console.log("Test from example: "+PP_IP.time) //this is for debug
         console.log("Test: "+PP_IP) //this is what I need
      }
      

      You cannot access the object in 'PP_IP.qml' file as PP_IP.time.
      You must create an instance first, e.g.

          PP_IP {
              id: pp_ip
          }
      

      Then use the id to print the time:

      console.debug(tt_ip.time)
      

      As for giving the context variable PP_IP the same name as your QML type defined by 'PP_IP.qml', that won't work either.
      The context variable's name gets masked by the Type name.

      If you want to use both, give them different names.

      1 Reply Last reply
      1
      • P Offline
        P Offline
        poucz
        wrote on last edited by
        #3

        Thank for your reply.

        Sorry maybe I describe my problem wrong, or I don't understand your answer.

        I set contex propertyin C++:

        engine.rootContext()->setContextProperty("PP_IP", QVariant("192.168.100.195"));
        

        When I run my program, and show "mypage.qml" - everythink is OK - console log IP "192.168.100.195" .

        Now when I use qmlscene to show "mypage.qml" , the property PP_IP is not set (because C++ code not run).
        So I want set these variable by dummy data. How can I do this?

        I need print IP adress 192.168.100.195 - when I run mypage.qml from qmlscene.
        Can you post dummydata/exmaple.qml for me?

        Thank you for your patience!!

        //mypage.qml
        Rectangle{
            Component.onCompleted: {
               console.log("Test: "+PP_IP) //print IP adress 
            }
        }
        
        DiracsbracketD 1 Reply Last reply
        0
        • P poucz

          Thank for your reply.

          Sorry maybe I describe my problem wrong, or I don't understand your answer.

          I set contex propertyin C++:

          engine.rootContext()->setContextProperty("PP_IP", QVariant("192.168.100.195"));
          

          When I run my program, and show "mypage.qml" - everythink is OK - console log IP "192.168.100.195" .

          Now when I use qmlscene to show "mypage.qml" , the property PP_IP is not set (because C++ code not run).
          So I want set these variable by dummy data. How can I do this?

          I need print IP adress 192.168.100.195 - when I run mypage.qml from qmlscene.
          Can you post dummydata/exmaple.qml for me?

          Thank you for your patience!!

          //mypage.qml
          Rectangle{
              Component.onCompleted: {
                 console.log("Test: "+PP_IP) //print IP adress 
              }
          }
          
          DiracsbracketD Offline
          DiracsbracketD Offline
          Diracsbracket
          wrote on last edited by Diracsbracket
          #4
          This post is deleted!
          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
          • Unsolved