先推荐一个处理markdown表格的网站,超级好用:markdown表格处理,我就是用这个表格处理的excel中的数据上传。
下表整理了数据类型的值范围、签名、qt如何定义等内容。
| 类型 | 范围/子类型 | dbus签名 | qt支持的签名 | qt类型定义方式 | 转换为variant |
|------------|-------------------------------------------|-----------|-----------|--------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| int8(c) | -128~127 | y | y | quint8/uchar | |
| uint8 | 0~255 | y | y | quint8/uchar | |
| int16 | -32768~32767 | n | n | qint16/short | QVariant::fromValue(arg) |
| uint16 | 0~65535 | q | q | quint16/ushort | QVariant::fromValue(arg) |
| int32 | -2147483648~2147483647 | i | i | qint32/int | |
| uint32 | 0~4294967295 | u | u | quint32/uint | |
| int64 | -9223372036854775808~9223372036854775807 | x | x | qint64/qlonglong | |
| uint64 | 0~18446744073709551615 | t | t | quint64/qulonglong | |
| float32(f) | -3.4E38 -1~+3.4E38+1 | d | d | double | |
| float64 | -1.79E+308 ~ +1.79E+308 | d | d | double | |
| bool | | b | b | bool | |
| string | | s | s | QString | |
| void | | | | | |
| array | ac | ay | ay | QByteArray data; | QVariantMap data; QList<uint> auint; auint.append(0); data["arg"] = QVariant::fromValue(auint); QVariant vrt; vrt.setValue<QVariantMap>(data); |
| | ay | ay | ay | QByteArray | QVariantMap data; QList<uint> auint; auint.append(0); data["arg"] = QVariant::fromValue(auint); QVariant vrt; vrt.setValue<QVariantMap>(data); | |
| | an | an | an | QList<short> | QVariantMap data; QList<uint> auint; auint.append(0); data["arg"] = QVariant::fromValue(auint); QVariant vrt; vrt.setValue<QVariantMap>(data); | |
| | aq | aq | aq | QList<ushort> | QVariantMap data; QList<uint> auint; auint.append(0); data["arg"] = QVariant::fromValue(auint); QVariant vrt; vrt.setValue<QVariantMap>(data); | |
| | ai | ai | ai | QList<int> | QVariantMap data; QList<uint> auint; auint.append(0); data["arg"] = QVariant::fromValue(auint); QVariant vrt; vrt.setValue<QVariantMap>(data); | |
| | au | au | au | QList<uint> | QVariantMap data; QList<uint> auint; auint.append(0); data["arg"] = QVariant::fromValue(auint); QVariant vrt; vrt.setValue<QVariantMap>(data); | |
| | ax | ax | ax | QList<qlonglong> | QVariantMap data; QList<uint> auint; auint.append(0); data["arg"] = QVariant::fromValue(auint); QVariant vrt; vrt.setValue<QVariantMap>(data); | |
| | at | at | at | QList<qulonglong> | QVariantMap data; QList<uint> auint; auint.append(0); data["arg"] = QVariant::fromValue(auint); QVariant vrt; vrt.setValue<QVariantMap>(data); | |
| | af | ad | ad | QList<double> | QVariantMap data; QList<uint> auint; auint.append(0); data["arg"] = QVariant::fromValue(auint); QVariant vrt; vrt.setValue<QVariantMap>(data); | |
| | ad | ad | ad | QList<double> | QVariantMap data; QList<uint> auint; auint.append(0); data["arg"] = QVariant::fromValue(auint); QVariant vrt; vrt.setValue<QVariantMap>(data); | |
| | ab | ab | ab | QList<bool> | QVariantMap data; QList<uint> auint; auint.append(0); data["arg"] = QVariant::fromValue(auint); QVariant vrt; vrt.setValue<QVariantMap>(data); | |
| | as | as | as | QStringList | QVariantMap data; QList<uint> auint; auint.append(0); data["arg"] = QVariant::fromValue(auint); QVariant vrt; vrt.setValue<QVariantMap>(data); | |
| variant | | v | v | QVariant | |
| map | a{sy} | a{sy} | a{sy} | QMap<QString, uchar> | map转variant: QMap<QString, QVariant> data; data.insert("key1", 1); data.insert("key2", "2a"); data.insert("key3", 3.23); data.insert("中文key", false); // QVariant datav = QVariant::fromValue(data); QMap<QString, QMap<QString, QVariant>> data1; data1.insert("key", data); QVariant vrt = QVariant::fromValue(data1); |
| | a{sn} | a{sn} | a{sn} | QMap<QString, short> | map转variant: QMap<QString, QVariant> data; data.insert("key1", 1); data.insert("key2", "2a"); data.insert("key3", 3.23); data.insert("中文key", false); // QVariant datav = QVariant::fromValue(data); QMap<QString, QMap<QString, QVariant>> data1; data1.insert("key", data); QVariant vrt = QVariant::fromValue(data1); | |
| | a{sq} | a{sq} | a{sq} | QMap<QString, ushort> | map转variant: QMap<QString, QVariant> data; data.insert("key1", 1); data.insert("key2", "2a"); data.insert("key3", 3.23); data.insert("中文key", false); // QVariant datav = QVariant::fromValue(data); QMap<QString, QMap<QString, QVariant>> data1; data1.insert("key", data); QVariant vrt = QVariant::fromValue(data1); | |
| | a{si} | a{si} | a{si} | QMap<QString, int> | map转variant: QMap<QString, QVariant> data; data.insert("key1", 1); data.insert("key2", "2a"); data.insert("key3", 3.23); data.insert("中文key", false); // QVariant datav = QVariant::fromValue(data); QMap<QString, QMap<QString, QVariant>> data1; data1.insert("key", data); QVariant vrt = QVariant::fromValue(data1); | |
| | a{su} | a{su} | a{su} | QMap<QString, uint> | map转variant: QMap<QString, QVariant> data; data.insert("key1", 1); data.insert("key2", "2a"); data.insert("key3", 3.23); data.insert("中文key", false); // QVariant datav = QVariant::fromValue(data); QMap<QString, QMap<QString, QVariant>> data1; data1.insert("key", data); QVariant vrt = QVariant::fromValue(data1); | |
| | a{sx} | a{sx} | a{sx} | QMap<QString, qlonglong> | map转variant: QMap<QString, QVariant> data; data.insert("key1", 1); data.insert("key2", "2a"); data.insert("key3", 3.23); data.insert("中文key", false); // QVariant datav = QVariant::fromValue(data); QMap<QString, QMap<QString, QVariant>> data1; data1.insert("key", data); QVariant vrt = QVariant::fromValue(data1); | |
| | a{st} | a{st} | a{st} | QMap<QString, qulonglong> | map转variant: QMap<QString, QVariant> data; data.insert("key1", 1); data.insert("key2", "2a"); data.insert("key3", 3.23); data.insert("中文key", false); // QVariant datav = QVariant::fromValue(data); QMap<QString, QMap<QString, QVariant>> data1; data1.insert("key", data); QVariant vrt = QVariant::fromValue(data1); | |
| | a{ss} | a{ss} | a{ss} | QMap<QString, QString> | map转variant: QMap<QString, QVariant> data; data.insert("key1", 1); data.insert("key2", "2a"); data.insert("key3", 3.23); data.insert("中文key", false); // QVariant datav = QVariant::fromValue(data); QMap<QString, QMap<QString, QVariant>> data1; data1.insert("key", data); QVariant vrt = QVariant::fromValue(data1); | |
| | a{sd} | a{sd} | a{sd} | QMap<QString, double> | map转variant: QMap<QString, QVariant> data; data.insert("key1", 1); data.insert("key2", "2a"); data.insert("key3", 3.23); data.insert("中文key", false); // QVariant datav = QVariant::fromValue(data); QMap<QString, QMap<QString, QVariant>> data1; data1.insert("key", data); QVariant vrt = QVariant::fromValue(data1); | |
| | a{sb} | a{sb} | a{sb} | QMap<QString, bool> | map转variant: QMap<QString, QVariant> data; data.insert("key1", 1); data.insert("key2", "2a"); data.insert("key3", 3.23); data.insert("中文key", false); // QVariant datav = QVariant::fromValue(data); QMap<QString, QMap<QString, QVariant>> data1; data1.insert("key", data); QVariant vrt = QVariant::fromValue(data1); | |
| | a{sa} | a{sa} | a{sa} | QMap<QString, QStringList> | map转variant: QMap<QString, QVariant> data; data.insert("key1", 1); data.insert("key2", "2a"); data.insert("key3", 3.23); data.insert("中文key", false); // QVariant datav = QVariant::fromValue(data); QMap<QString, QMap<QString, QVariant>> data1; data1.insert("key", data); QVariant vrt = QVariant::fromValue(data1); | |
| | a{sv} | a{sv} | a{sv} | QMap<QString, QVariant> | map转variant: QMap<QString, QVariant> data; data.insert("key1", 1); data.insert("key2", "2a"); data.insert("key3", 3.23); data.insert("中文key", false); // QVariant datav = QVariant::fromValue(data); QMap<QString, QMap<QString, QVariant>> data1; data1.insert("key", data); QVariant vrt = QVariant::fromValue(data1); | |
| | a{sa{sv}} | a{sa{sv}} | a{sa{sv}} | QMap<QString, QMap<QString, QVariant>> | map转variant: QMap<QString, QVariant> data; data.insert("key1", 1); data.insert("key2", "2a"); data.insert("key3", 3.23); data.insert("中文key", false); // QVariant datav = QVariant::fromValue(data); QMap<QString, QMap<QString, QVariant>> data1; data1.insert("key", data); QVariant vrt = QVariant::fromValue(data1); | |
| | a{yv}、a{nv}...a{dv} | a{yv} | 不支持 | / | 这种场景的构造可以使用d-feet或用gdbus |
| | a{bv}、a{av}没有这种以bool或数组作为key值 | | | | |
数据说明:
1、qt不支持int8,只支持quint8或uchar,默认范围是0-255。如果qt定义此范围外的数据,会自动转换,比如-1会转成255,256会转成0。
2、qt不支持uint8的数组,只支持QByteArray,默认范围是-128-127。如果是此范围外的数据,qt会自动转换,比如255会转成-1, 250会转成-6。但是dbus支持的范围是0-255,所以-1或者-6到dbus后,又会被转为255或250。
备注:
1、QVariantMap定义的、不管是几层嵌套,其实签名都是a{sv}--[map[string]dbus.Variant] 。
2、QVariantMap相当于QMap<QString, QVariant>。