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. QML (JavaScript) how to create dynamic object?
Forum Updated to NodeBB v4.3 + New Features

QML (JavaScript) how to create dynamic object?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 345 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.
  • K Offline
    K Offline
    Kycho
    wrote on last edited by Kycho
    #1

    The createRoom function does not work.
    What I want is to create a Dynamic Room object inside the RoomPage.

    How can I solve this problem?

    RoomSelect.qml

    import QtQuick 2.4
    
    RoomSelectForm {
        function createRoom(id,name,type,price,visible){
            var component;
            var object;
            component = Qt.createComponent("Room.qml")
            object  = component.createObject(roomPage2.roomLayout,{"x":0 , "y" : 0});
            object.roomId = id;
            object.roomName = name;
            object.roomType = type;
            object.roomPrice = price;
            object.roomVisible = visible;
            return object;
        }
    }
    

    RoomSelectForm.ui.qml

    import QtQuick 2.4
    import QtQuick.Controls 2.3
    import QtQuick.Layouts 1.3
    
    Item {
        id: item1
        property alias roomPage2: roomPage2
    
    // blablablabla...
    
            SwipeView {
                id: swipeView
    
                RoomPage{
                    id:roomPage1
                }
                RoomPage{
                    id:roomPage2
                }
                RoomPage{
                    id:roomPage3
                }
        }
    }
    
    

    RoomPage.qml

    import QtQuick 2.0
    import QtQuick.Layouts 1.3
    import QtQuick.Controls 2.2
    
    Item {
        property alias roomLayout: roomLayout
    
    // blablablablabla...
    
            GridLayout {
                id: roomLayout
            }
    }
    

    Room.qml

    import QtQuick 2.4
    
    Item {
        property int roomId: -1
        property alias roomName: roomName.text
        property alias roomType: roomType.text
        property alias roomPrice: roomPrice.text
        property alias roomVisible: room.visible
    
    Rectangle{
    // blablablablabla...
    }
    
    }
    

    please help me....

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Does not work means ? What is the behavior ? You are creating local variable. Did you observe that ?

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      K 1 Reply Last reply
      2
      • dheerendraD dheerendra

        Does not work means ? What is the behavior ? You are creating local variable. Did you observe that ?

        K Offline
        K Offline
        Kycho
        wrote on last edited by Kycho
        #3

        @dheerendra

        Sorry.
        Some content is missing.

        I want to call the createRoom function in C ++.

        main.cpp

            QQmlEngine *engine = ui->quickWidget->engine();
        
            QQmlComponent qml_RoomSelectCom(engine,QUrl("qrc:/RoomSelect.qml"));
        
            QObject *qml_RoomSelectObj = qml_RoomSelectCom.create();
        
            QVariant qml_rooms;
        
        QMetaObject::invokeMethod(qml_RoomSelectObj,"createRoom",Q_RETURN_ARG(QVariant,qml_rooms),Q_ARG(QVariant,5),Q_ARG(QVariant,"Test"),Q_ARG(QVariant,"wqe"),Q_ARG(QVariant,"1230"),Q_ARG(QVariant,true));
           
        

        The createRoom function is executed but the Room object does not appear on the screen.
        I think the use of this invokeMethod function seems to be wrong.

        How can I solve it?

        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