[Interest] Namespace on Custom C++ property in QML?

Alan Alpert 416365416c at gmail.com
Mon Feb 25 19:48:19 CET 2013


On Mon, Feb 25, 2013 at 5:56 AM, Charley Bay <charleyb123 at gmail.com> wrote:
> I'm sure this is a silly question, but why are these different:
>
> // FILE: MyItem0.qml
> import QtQuick 2.0
> import my.custom.cpp 1.0    //<==NOTE NO "as"
>
> Item {
>   property MyCppType myCppType // WORKS
> }
>
> // FILE: MyItem1.qml
> import QtQuick 2.0
> import my.custom.cpp 1.0 as MyCpp   //<==NOTE "as"
>
> Item {
>   property MyCpp.MyCppType myCppType // NOT WORK
> }
>
> QUESTION:  If I import the C++ custom types with an "as MyCpp", then I can
> no longer use the type as a "property" within QML.  Dropping the "as-module"
> name works.
>
> The compile error is at the "dot" separating the "MyCpp" from "MyCppType",
> with an error:
>
>>  property MyCpp.MyCppType myCppType
>>             ^
>>   "Unexpected token '.'"
>
>
> I assume package/namespace/plugin scoping names are not allowed for defining
> properties in QML?  Does this mean you can't use "as-namespaces" in a QML
> file when you want that C++ type as a "property"?

I wouldn't so much say "not allowed" as not working. This looks like a
bug to me, please file it at bugreports.qt-project.org .

--
Alan Alpert



More information about the Interest mailing list