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

QML: Set Property of Nested ListElement

From Dev

Expose abstract type as Q_PROPERTY to QML

From Dev

How to bind to root context object signal from QML

From Dev

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

From Dev

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

From Dev

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

From Dev

QML: Conditionally set different properties of a property group

From Dev

QML On Item Changed Signal

From Dev

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

From Dev

Exposing an enum in a QML signal

From Dev

How to expose property of QObject pointer to QML

From Dev

Access property set with setProperty from QML

From Dev

How to access a component bound to a property in QML

From Dev

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

From Dev

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

From Dev

get the type of the parameter in a set property

From Dev

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

From Dev

QML: How to reset item property to defaut

From Dev

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

From Dev

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

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 Cannot emit signal if it has same name as property

From Dev

How to set property type of qml signal?

From Dev

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

From Dev

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

From Dev

Signal between QML with Repeater

From Dev

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

From Dev

QML how to set color in a mouseArea

Related Related

  1. 1

    QML: Set Property of Nested ListElement

  2. 2

    Expose abstract type as Q_PROPERTY to QML

  3. 3

    How to bind to root context object signal from QML

  4. 4

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

  5. 5

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

  6. 6

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

  7. 7

    QML: Conditionally set different properties of a property group

  8. 8

    QML On Item Changed Signal

  9. 9

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

  10. 10

    Exposing an enum in a QML signal

  11. 11

    How to expose property of QObject pointer to QML

  12. 12

    Access property set with setProperty from QML

  13. 13

    How to access a component bound to a property in QML

  14. 14

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

  15. 15

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

  16. 16

    get the type of the parameter in a set property

  17. 17

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

  18. 18

    QML: How to reset item property to defaut

  19. 19

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

  20. 20

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

  21. 21

    Expose abstract type as Q_PROPERTY to QML

  22. 22

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

  23. 23

    QML Cannot emit signal if it has same name as property

  24. 24

    How to set property type of qml signal?

  25. 25

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

  26. 26

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

  27. 27

    Signal between QML with Repeater

  28. 28

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

  29. 29

    QML how to set color in a mouseArea

HotTag

Archive