QMap Class
The QMap class is a template class that provides a red-black-tree-based dictionary.
Header: #include
qmake: QT += core
//Declare
QMap<QString, int>map
//Use Operator
map['one'] = 1;
map['three'] = 3;
map['seven'] = 7;
//insert value
map.insert('twelve' ,12);
// use operator[]
int num1 = map["thirteen"]
int num2 = map["thirteen"]
//
int timeout = 30;
if(map.contains("TIMEOUT"));
timeout = map.value("TIMEOUT");
//
QMapIterator<QString, int> i(map);
while (i.hasNext()) {
i.next();
cout << i.key() << ": " << i.value() << Qt::endl;
}
QSharedPointer Class
Header: #include
qmake: QT += core
The QSharedPointer is an automatic, shared pointer in C++. It behaves exactly like a normal pointer for normal purposes, including respect for constness. QSharedPointer will delete the pointer it is holding when it goes out of scope, provided no other QSharedPointer objects are referencing it.
线程安全
QSharedPointer and QWeakPointer are reentrant classes. This means that, in general, a given QSharedPointer or QWeakPointer object cannot be accessed by multiple threads at the same time without synchronization.