You can't as QHash and QValue lack a method for inserting that returns a reference to the container. So you can't chain method calls.

try
Qt Code:
  1. template<typename KEY,typename VALUE>
  2. struct MapConstructor : public QMap<KEY,VALUE>
  3. {
  4. MapConstructor<KEY,VALUE>& insert(const KEY &key, const VALUE &value)
  5. {
  6. QMap<KEY,VALUE>::insert(key, value);
  7. return *this;
  8. }
  9. };
  10.  
  11. QMap<QString,int> aMap = MapConstructor<QString,int>().insert("hello",5).insert("world",5).insert("hell",4);
To copy to clipboard, switch view to plain text mode 

or you could take a look at Boost.Assign, so you don't have to reinvent the wheel.