How to correctly remove an item from the map by key?

How to correctly remove an item from the map by key?

There is such a task: to delete items from the QMap by key.

There is such a task: to delete items from the QMap by key.

I do this with this code.

QMap <int, QString> map;
map.insert(0, "0");
map.insert(1, "1");
map.insert(2, "2");
map.insert(3, "3");
map.insert(4, "4");
map.insert(5, "5");

qDebug() << "Before:"; for (auto i = 0; i < map.size(); i++) qDebug() << map.value(i) << "\t"; qDebug() << "--------------";

map.remove(3);

qDebug() << "After:"; for (auto i = 0; i < map.size(); i++) qDebug() << map.value(i) << "\t";

I have the following result:

Before: "0" "1" "2" "3" "4" "5"


After: "0" "1" "2" "" "4"

But I expect the result to be:

Before: "0" "1" "2" "3" "4" "5"

After:

"0" "1" "2" "4" "5"

Please tell me what is wrong?

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

C/C++ vs. Rust: A developer’s perspective

In this post, you'll see the difference between Rust and C/C++ in a developer’s perspective

Variable Introduction in C#[Bangla]

LIKE | COMMENT | SHARE | SUBSCRIBE A variable is nothing but a name given to a storage area that our programs can manipulate. Each variable in C# has a speci...