How to set property type of qml signal?

PaleNeutron

I am learning qml,quick and pyqt5 and write a small test script.

In this script, I want to drop something on my UI and print the url of it.

test.qml

import QtQuick 2.3

Rectangle {
    id : root
    signal clicked(int x, int y)
    signal filedroped(list url)
    width: 800
    height: 450

    MouseArea {
        anchors.fill: parent
        onClicked: {
            parent.clicked(mouseX, mouseY)
        }
        DropArea {
            anchors.fill: parent
            onDropped: {
            root.filedroped(drop.urls)
            }
        } 
    }
}

The doc says:Any of the QML Basic Types aside from the enumeration type can be used as custom property types.

But I got error like this in signal filedroped:

Invalid signal parameter type: list

Also, I have tried urllist and string.
urllist failed and string works.

What's wrong with my script?

EDIT

Since I use qml with pyqt, I do not want to use the type var.
With var, I'll got a QJSValue object instead of basic type of python in my python script.
Why qml performs different with the official document? Is the document wrong?

Yoann Quenach de Quivillic

It seems on there's indeed an error in the Qt Documentation. It is said (here) that

the allowed parameter types [for signal parameters] are the same as those listed under Defining Property Attributes on this page.

Yet one can define a property as follow:

property list<Item> items

whereas this is invalid:

signal mysignal(list<Item> items)

But anyway, the QML list type was not a solution. The official documentation is quite clear:

A list can only store QML objects, and cannot contain any basic type values. (To store basic types within a list, use the var type instead.).

In other words you can't use list to store strings, url, int. You have to use var. Another solution would be to use a formatted string with a custom separator instead of your url list, and split it on the Python side.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to set property type of qml signal?

From Dev

How to use a custom Qt type with a QML signal?

From Dev

How to catch C++ signal in QML signal handler after type registration?

From Dev

How to catch C++ signal in QML signal handler after type registration?

From Dev

QML: Set Property of Nested ListElement

From Dev

QML Cannot emit signal if it has same name as property

From Dev

Access property set with setProperty from QML

From Dev

QML: Conditionally set different properties of a property group

From Dev

Expose abstract type as Q_PROPERTY to QML

From Dev

Expose abstract type as Q_PROPERTY to QML

From Dev

QML: Using cpp signal in QML always results in "Cannot assign to non-existent property"

From Dev

QML: Using cpp signal in QML always results in "Cannot assign to non-existent property"

From Dev

How to set a property of a typed object while retaining it's type?

From Dev

jackson jsonSchema: How to set type object for property (JsonRawValue)

From Dev

QML how to set color in a mouseArea

From Dev

Not able to use imported type as property type in QML when imported with qualifier

From Dev

How to bind to a signal from a delegate component within a ListView in QML

From Dev

How to connect a qml child component signal to a c++ slot

From Dev

How can I listen to a C++ signal from QML?

From Dev

How to bind to root context object signal from QML

From Dev

Qt-how to connect a function to a signal in qml with python? using QQmlApplicationEngine

From Dev

get the type of the parameter in a set property

From Dev

QML On Item Changed Signal

From Dev

Exposing an enum in a QML signal

From Dev

Signal between QML with Repeater

From Dev

How to access a component bound to a property in QML

From Dev

How to expose property of QObject pointer to QML

From Dev

QML: How to reset item property to defaut

From Dev

How to change a property of a object in QML upon a hover?

Related Related

  1. 1

    How to set property type of qml signal?

  2. 2

    How to use a custom Qt type with a QML signal?

  3. 3

    How to catch C++ signal in QML signal handler after type registration?

  4. 4

    How to catch C++ signal in QML signal handler after type registration?

  5. 5

    QML: Set Property of Nested ListElement

  6. 6

    QML Cannot emit signal if it has same name as property

  7. 7

    Access property set with setProperty from QML

  8. 8

    QML: Conditionally set different properties of a property group

  9. 9

    Expose abstract type as Q_PROPERTY to QML

  10. 10

    Expose abstract type as Q_PROPERTY to QML

  11. 11

    QML: Using cpp signal in QML always results in "Cannot assign to non-existent property"

  12. 12

    QML: Using cpp signal in QML always results in "Cannot assign to non-existent property"

  13. 13

    How to set a property of a typed object while retaining it's type?

  14. 14

    jackson jsonSchema: How to set type object for property (JsonRawValue)

  15. 15

    QML how to set color in a mouseArea

  16. 16

    Not able to use imported type as property type in QML when imported with qualifier

  17. 17

    How to bind to a signal from a delegate component within a ListView in QML

  18. 18

    How to connect a qml child component signal to a c++ slot

  19. 19

    How can I listen to a C++ signal from QML?

  20. 20

    How to bind to root context object signal from QML

  21. 21

    Qt-how to connect a function to a signal in qml with python? using QQmlApplicationEngine

  22. 22

    get the type of the parameter in a set property

  23. 23

    QML On Item Changed Signal

  24. 24

    Exposing an enum in a QML signal

  25. 25

    Signal between QML with Repeater

  26. 26

    How to access a component bound to a property in QML

  27. 27

    How to expose property of QObject pointer to QML

  28. 28

    QML: How to reset item property to defaut

  29. 29

    How to change a property of a object in QML upon a hover?

HotTag

Archive