Question: I need to get a unique ID for the device. I originally thought I'd use the device's imei, but that doesn't seem to return anything:

```
import QtSystemInfo 5.0

DeviceInfo {
    id: device
}

Component.onCompleted {
    console.log(device.imei(0)) // Returns nothing
}

```

That may or may not be a bug: <https://bugs.launchpad.net/ubuntu/+source/qtsystems-opensource-src/+bug/1197542> but since there haven't been any updates for a year, I'm hoping that maybe I can use some other piece of information.

So, does anyone know how I can get a unique ID for the device? It has to be persistent, but it can be totally meaningless other than as an identifier.

Answer: 
As dobey said, there's no way to get the IMEI in confined apps, so I gave up on trying to get an ID based on the device itself. Instead, I just generate a UUID and store it in U1DB.

```
// uuid.js
.pragma library

function generateUUID(){
    var d = new Date().getTime();
    var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
        var r = (d + Math.random()*16)%16 | 0;
        d = Math.floor(d/16);
        return (c === 'x' ? r : (r&0x3|0x8)).toString(16);
    });
    return uuid;
};

// Elsewhere
U1db.Database {
    id: db
    path: "settings"
}

U1db.Document {
    id: user
    database: db
    docId: "user"
    create: true
    defaults: {
        "userId": ""
    }
}

// Somewhere I need the userId
Item {
    id: thing

    Component.onCompleted: {
        userId: user.contents.userId
        if (!userId) {
             userId = Uuid.generateUUID()
             var userContents = user.contents
             userContents.userId = userId
             user.contents = userContents
        }
        return userId
    }
}

```
In more recent versions, the `DeviceInfo` QML type has a `uniqueID` property:

```
DeviceInfo {
    id: device
}

Component.onCompleted {
    console.log(device.uniqueID)
}

```

Documentation: [QML DeviceInfo Element: property uniqueID](https://doc-snapshots.qt.io/qt-mobility/qml-deviceinfo.html#uniqueID-prop). (Code not tested, just saw this in the documentation.)