#includeint main() { // Create a QJsonObject QJsonObject obj; obj["name"] = "John"; obj["age"] = 30; // Iterate through the object using constBegin and constEnd for(auto it = obj.constBegin(); it != obj.constEnd(); ++it) { qDebug() << it.key() << ":" << it.value().toString(); } return 0; }
#includeThis code creates a QJsonObject with two key-value pairs, and uses constBegin and constEnd to iterate through them and print their values. This example uses the QtGui and QtWidgets package libraries.#include int main() { // Create a QJsonObject QJsonObject obj; obj["color"] = "red"; obj["size"] = "small"; // Iterate through the object using constBegin and constEnd for(auto it = obj.constBegin(); it != obj.constEnd(); ++it) { qDebug() << it.key() << ":" << it.value().toString(); } return 0; }