[Qt-qml] How to remove warnings from QML file

1,500 views
Skip to first unread message

manoj jangra

unread,
Mar 12, 2012, 6:27:20 AM3/12/12
to qt-...@qt.nokia.com
Hello All,
 
I'm getting warnings (Unable to assign [undefined] to QString text) while trying to load data into a gridmenu in QML from C++ files.
In QML file I load this data by declaring source as "source:  model.image". and set the model data from C++ file.
Data is loaded successfully but I'm getting warnings as mentioned above.
 
Can anyone please help me out in getting rid of these warnings??

--
WIth Best Regards
Manoj

Save a Paper; Save a Tree....

Sven Anderson

unread,
Mar 12, 2012, 7:25:20 AM3/12/12
to qt-...@qt.nokia.com
Hi Manoj

On 12.03.2012 11:27, manoj jangra wrote:
> I'm getting warnings (Unable to assign [undefined] to QString text)
> while trying to load data into a gridmenu in QML from C++ files.
> In QML file I load this data by declaring source as
> "source:model.image". and set the model data from C++ file.
> Data is loaded successfully but I'm getting warnings as mentioned above.
> Can anyone please help me out in getting rid of these warnings??

you don't give much information here, but probably your QML item is
created before the model data has been created by the C++ code. So in
the meantime some strings are bound to undefined values, that's why you
get the warning. You have to make sure, that the data is available when
your QML stuff is instantiated or at least initialize it with empty strings.


Best regards

Sven
_______________________________________________
Qt-qml mailing list
Qt-...@qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-qml

Johannes Zellner

unread,
Mar 12, 2012, 7:35:44 AM3/12/12
to qt-...@qt.nokia.com
Hi Manoj,

On 03/12/2012 11:27 AM, ext manoj jangra wrote:
> Hello All,
> I'm getting warnings (Unable to assign [undefined] to QString text)
> while trying to load data into a gridmenu in QML from C++ files.
> In QML file I load this data by declaring source as
> "source:model.image". and set the model data from C++ file.
> Data is loaded successfully but I'm getting warnings as mentioned above.
> Can anyone please help me out in getting rid of these warnings??

You might want to check in the binding if the string value you try to
assign is valid.
eg.

Text {
text: myValue ? myValue : ""
}


Regards,

Johannes

manoj jangra

unread,
Mar 13, 2012, 1:08:44 AM3/13/12
to Johannes Zellner, qt-...@qt.nokia.com
Thanks, it worked.. :)

manoj jangra

unread,
Mar 13, 2012, 1:47:56 AM3/13/12
to Johannes Zellner, qt-...@qt.nokia.com
Hi Johannes,

Thanks for your valuable suggestion, it worked fine in most of the cases where i was setting text values from model data.
But I still have same issue with "model" property in QML ListView.
I tried setting model value as suggested by you: 
model: myModel ? myModel : ""

But its still giving me warning which says "ReferenceError: Can't find variable: myModel"

I'm getting the data but want to get rid of this warning; is there any way i can do it??

Sven Anderson

unread,
Mar 13, 2012, 5:58:37 AM3/13/12
to qt-...@qt.nokia.com
Hi Manoj,

On 13.03.2012 06:47, manoj jangra wrote:
> Thanks for your valuable suggestion, it worked fine in most of the cases
> where i was setting text values from model data.
> But I still have same issue with "model" property in QML ListView.
> I tried setting model value as suggested by you:
> model:myModel?myModel:""
>
> But its still giving me warning which says "ReferenceError: Can't find
> variable: myModel"
>
> I'm getting the data but want to get rid of this warning; is there any
> way i can do it??

Did you read my email? ;-)

Sven

manoj jangra

unread,
Mar 13, 2012, 6:32:32 AM3/13/12
to Sven Anderson, qt-...@qt.nokia.com
Hi Seven,
 
Yes, I saw your email; thanks for the comments. The problem is same, QML is initialized before setting data in C++.
But the condition i'm applying to initialize qml with empty string is not working out in case of setting model value; but working well while setting text value.
As mentioned in previous mail. Do you have any suggestion on that??

Sven Anderson

unread,
Mar 13, 2012, 7:09:01 AM3/13/12
to manoj jangra, qt-...@qt.nokia.com
Hi Manoj,

On 13.03.2012 11:32, manoj jangra wrote:
> Hi Seven,
> Yes, I saw your email; thanks for the comments. The problem is same, QML
> is initialized before setting data in C++.

That's the problem. You need to set the data before or while (e.g. in
the constructor of a C++ implemented QML item) the QML is initialized.

Reply all
Reply to author
Forward
0 new messages