About Qml: Where the 'object' come from?

#1

Hello guys,
i am trying to read the QGC code for second devolopement.
i am QML freshman. and there is a problem bother me a lot, Would be nice to tell me about the answer.

:slight_smile:in file PlanView.qml, there is a var ‘object’, as show below, where this ‘object’ declared, and where it come from?

        // Add the vehicles to the map

        MapItemView {

            model: QGroundControl.multiVehicleManager.vehicles

            delegate:

                VehicleMapItem {

                vehicle:           object       ////------where this 'object' come from?

                coordinate:     object.coordinate  ////------where this 'object' come from?

                map:            editorMap

                size:           ScreenTools.defaultFontPixelHeight * 3

                z:              QGroundControl.zOrderMapItems - 1

            }

        }

thanks a lot.

#2

QGroundControl.multiVehicleManager.vehicles is a QmlObjectListModel. “object” is one of the "roles"per the QAbstractListModel implemenation.

#3

:slight_smile:Thanks for reply.

#4

Thanks for reply. i do know the ‘object’ is from the QmlObjectListModel, and it is one of the “roles”, as you said. But i can’t find where this ‘object’ declare, i am a C/C++ programer, usually, if there is a var, you should declare it first, then use it. for this ‘object’ we talk about, i can’t trace the position where it declare! , can you tell me the reason, or some clue? thanks.

#5
QHash<int, QByteArray> QmlObjectListModel::roleNames(void) const
{
    QHash<int, QByteArray> hash;
    
    hash[ObjectRole] = "object";
    hash[TextRole] = "text";
    
    return hash;
}
1 Like
#6

Thank you for your answer, really appreciate.:rose:@DonLakeFlyer