Do all of your structures consist solely of three integer values and the first value is always the "identifier" for the structure type? If so, you can simplify and use a single structure, which you can store in the QMap or more likely, store a pointer to the structure in the QMap.
If you really have a need to define a bunch of different structure types in the QMap, you can use a void pointer, such as:
// int is the key to the map and is the structure identifier/type, i.e. 1001, 1002, 1003, 1004, etc.
// void* is a pointer to the structure type, i.e. user_input*, batt_status*, etc.
QMap<int, void*> struct_map;
struct_map.insert(1001, new user_input);
struct_map.insert(1004, new batt_status);
// int is the key to the map and is the structure identifier/type, i.e. 1001, 1002, 1003, 1004, etc.
// void* is a pointer to the structure type, i.e. user_input*, batt_status*, etc.
QMap<int, void*> struct_map;
struct_map.insert(1001, new user_input);
struct_map.insert(1004, new batt_status);
To copy to clipboard, switch view to plain text mode
Then, to get the structure pointer out of the QMap, you cast the void* back to the correct structure pointer:
if (struct_map.contains(1001))
{
user_input *ui = static_cast<user_input*>(struct_map.value(1001));
// process user_input structure here
}
if (struct_map.contains(1004))
batt_status *bs = static_cast<batt_status*>(struct_map.value(1004));
// process batt_status here
}
if (struct_map.contains(1001))
{
user_input *ui = static_cast<user_input*>(struct_map.value(1001));
// process user_input structure here
}
if (struct_map.contains(1004))
batt_status *bs = static_cast<batt_status*>(struct_map.value(1004));
// process batt_status here
}
To copy to clipboard, switch view to plain text mode
Hope that helps.
Bookmarks