QListlist; list.insert(0, 10); // inserts 10 at the beginning list.append(20); // inserts 20 at the end
QListlist; list << "apple" << "banana" << "cherry"; list.insert(1, "orange"); // inserts "orange" at index 1, shifting "banana" to index 2
QListIn these examples, we can see how QList insert is used to add elements to a list at specific positions. The Qt library provides many other functions for working with lists, such as remove, replace, and indexOf.list; list << 1 << 2 << 3; QList toInsert; toInsert << 4 << 5; list.insert(2, toInsert); // inserts 4 and 5 at index 2, shifting 2 and 3 to indices 4 and 5