Better_Software_Header_Mobile Better_Software_Header_Web

Find what you need - explore our website and developer resources

Exploring GitHub Copilot Agent Mode in VS Code

Cross-Language Refactoring in C++/QML Projects

struct Data {
    QString name;
    QString flag;
    double population;
+   double size;
   }
enum Roles {
    NameRole = Qt::UserRole,
    FlagRole,
    PopulationRole,
+   SizeRole,
  };
QVariant MyModel::data(const QModelIndex &index, int role) const
  {
     // [...]
     switch (role) {
     // [...]
+    case SizeRole:
+      return data.size;
     // [....]
     }
  }
QHash<int, QByteArray> MyModel::roleNames() const
  {
     static QHash<int, QByteArray> mapping {
       {NameRole, "name"}, {FlagRole, "flag"},
       {PopulationRole, "population"},
+      {SizeRole, "size"},
     }
     return mapping;
  }
Text {
-   text: model.name + "\n" + "population: " + model.population.toFixed(3) + "mill.\n"
+   text: model.name + "\n" + "population: " + model.population.toFixed(3) + "mill.\n" + "size: " + model.size.toFixed(2) + " km2"
  }

About KDAB

JanMarker

Jan Marker

Senior Software Engineer

Sign up for the KDAB Newsletter

Learn Modern C++

Learn more