I tried the Cities example in the book C++ -GUI Programming with Qt 4 first ed., and i tried to set a header data string by using the row

cityModel.setHeaderData(0, Qt::Horizontal, QObject::tr("Name"));

in the main.cpp file.

The code can be compiled and run without any complaints but the added code has not any effects.

The code is
Qt Code:
  1. #include <QHeaderView>
  2. #include <QTableView>
  3.  
  4. #include "citymodel.h"
  5.  
  6. int main(int argc, char *argv[])
  7. {
  8. QApplication app(argc, argv);
  9.  
  10. QStringList cities;
  11. cities << "Arvika" << "Boden" << "Eskilstuna" /*<< "Falun"
  12.   << "Filipstad" << "Halmstad" << "Helsingborg" << "Karlstad"
  13.   << "Kiruna" << "Kramfors" << "Motala" << "Sandviken"
  14.   << "Skara" << "Stockholm" << "Sundsvall" << "Trelleborg" */ ;
  15. QStringList layers;
  16. layers << "l1" << "l2" << "l3" << "l4";
  17.  
  18. CityModel cityModel;
  19. cityModel.setCities(cities);
  20. cityModel.setLayers(layers);
  21.  
  22. QTableView tableView;
  23. tableView.setModel(&cityModel);
  24. tableView.setAlternatingRowColors(true);
  25. tableView.setWindowTitle(QObject::tr("Cities"));
  26.  
  27. cityModel.setHeaderData(0, Qt::Horizontal, QObject::tr("Name")); // <------
  28.  
  29. tableView.show();
  30.  
  31. return app.exec();
  32. }
To copy to clipboard, switch view to plain text mode 

How should you set and read header data in this case?

teele