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. how we can use qml as a class with some method and property in our app?
Qt 6.11 is out! See what's new in the release blog

how we can use qml as a class with some method and property in our app?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 1 Posters 713 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.
  • stackprogramerS Offline
    stackprogramerS Offline
    stackprogramer
    wrote on last edited by stackprogramer
    #1

    hi, i want to use myclass.qml for defining "myclass" class,with some property and some method in qml;
    myclass.qml

    import quick 2.0
    Window{id:myclass
    property1=1;
    property2=2;
    ...
    function f1(){}
    function f2(){}
    function f3(){}
    ..........
    
    
    
    }
    

    in main.qml i want to detect myclass detect for example:
    when i write these source:

    myclass.f1();
    myclass.property1();
    
    

    i can execute and run in my main.qml file.
    can any one help me?
    thanks for reply.

    1 Reply Last reply
    0
    • stackprogramerS Offline
      stackprogramerS Offline
      stackprogramer
      wrote on last edited by stackprogramer
      #2

      for more info, how main.qml can inheritance from myclass.qml?????????
      i write in main.qml this type.

      myclass{id:class1;}
      

      but the methods and the propery is undefined in main.qml!!!!!
      can any help me?
      i.e. when in my main.qml i write

      var x:class1.f1();
      

      the result is :

      f1 is not defined.
      
      1 Reply Last reply
      0
      • stackprogramerS Offline
        stackprogramerS Offline
        stackprogramer
        wrote on last edited by stackprogramer
        #3

        i after examine the qml i concluded that we define objects in myclass.qml,and for calling in my main.qml we define type:

        myclass{.....}
        

        this type inherited functions and attributes from myclass.qml and we can use it only in our main.qml file
        thanks for attention

        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