[Development] QML and UUID

Alan Alpert 416365416c at gmail.com
Tue Aug 19 19:34:25 CEST 2014


On Mon, Aug 18, 2014 at 4:59 PM, Thiago Macieira
<thiago.macieira at intel.com> wrote:
> On Tuesday 19 August 2014 01:36:54 Renaud wrote:
>> Hi all,
>>
>> I am running into issue when I try to use QQuickImageProvider and
>> QUUID.toString().
>>
>> I store my images into map<QString,QPixmap>. The key is the uuid
>> (stored as QString) from instances of my custom class.
>>
>> So, stored keys in the map are like this:
>> {22715e73-e6ca-4cca-a77d-fe68746b9f79}, but when my QML component asks
>> to the provider, the provider receives this kind of key:
>> "%7B22715e73-e6ca-4cca-a77d-fe68746b9f79%7D".
>>
>> It can not find any match. Is There a way to prevent the modification
>> in QML world ?
>> Of course, I can implement some workarounds, such as remove curly
>> braces or use other kind of key.  But it will be really painful.
>
> That's a URL transformation.
>
> How did the string come from QML world? Did you pass it to a function that
> expects a URL?

Yes, QtQuick image providers look like this in the QML file: Image {
source: "image://myimageprovider/key" } . The URL gets broken down and
the key gets sent to the appropriate QQuickImageProvider.

The idea is that the key should be something human readable, but if
you need to pass through machine-readable UUIDs then probably just use
the URL decoding functions on it.

See also: http://qt-project.org/doc/qt-5/qquickimageprovider.html,
http://qt-project.org/doc/qt-5/qurl.html#fromPercentEncoding

--
Alan Alpert



More information about the Development mailing list