CybeX
CybeX

Reputation: 2406

Unexpected Token `:' while defining QML signal parameter type

I am trying to familiarize myself with QML. I am following this Qt provide tutorial, but have run into a problem.

Problem:

While creating the Cell.qml file, I am required to create a clicked signal, where the single parameter named cellColor is defined as a color type (if I understand this correctly)

../QMLTest/Cell.qml:6 Unexpected token `:'

The code snippet in question from Cell.qml is:

import QtQuick 2.0

Item {
    id: container
    property alias cellColor: rectangle.color
    signal clicked(cellColor: color)                   <-----Problem - line 6

    width: 40; height: 25
    //...
}

Since QML uses Javascript, I figured I'll try this, which worked:

signal clicked(var cellColor)

One obvious drawback is you lose the defined type (based on my assumption earlier).

Question:

Why did the provided signal code not work, and is there any drawback to using the var keyword instead of defining the type?

Update

Added after answer was accepted.

I should also have mentioned, I am using Qt Creator 4.10.0 with Qt 5.13.1 (MSVC 32bit)

Upvotes: 0

Views: 2294

Answers (1)

Frank Osterfeld
Frank Osterfeld

Reputation: 25165

This syntax is new in Qt 5.14. It's following TypeScript syntax and the way to go for the upcoming QML 3. With older Qt versions, one gets the error message that you mentioned. The classical and so far still supported syntax would be

signal clicked(color cellColor)

The name: type syntax isn't even mentioned yet in the Qt documentation about QML signals.

Upvotes: 3

Related Questions