Reputation: 3190
Is a model in Qt supposed to more or less fit the mold—and therefore ultimately be represented by—a list, table or tree? What if your model is a lot more complex and cannot be represented by a list, table or tree?
If this were the case, I would think that would make a model nothing but data; something comparable to an XML file or a spreadsheet.
Example: What if the model within the application in question were something more complex, like a car? I would assume the model of a car would include all sort of data and business rules about the car. There would be an engine, wheels, a frame, and many other different components that all work together to create the entire car. Each component would have its own unique set of behaviors: the frame would have a color, the engine would have a temperature, the stereo would have a volume setting, and so forth. And each component would have behaviors too: if the gas pedal is pressed, the wheels rotate and the engine heats up. Obviously, a QStringListModel
or some other built-in, simplified model cannot appropriately address all of the complexities in a car.
Upvotes: 5
Views: 2167
Reputation: 79665
A model is not data but a set of callbacks. In fact, there need not be real data staying behind the model. It is more like a server to be queried.
This is like the difference between this:
int data[5] = { 0, 2, 4, 6, 8 };
void viewer(int *data, int n) {
for (int ii = 0; ii < n; ii++)
printf("%d, ", data[ii]);
}
int main() {
viewer(data, 5);
}
And this:
int model(int index) {
return index * 2;
}
typedef int (*model_function)(int);
void viewer(model_function model, int n) {
for (int ii = 0; ii < n; ii++)
printf("%d, ", model(ii));
}
int main() {
viewer(model, 5);
}
Both will give you 0, 2, 4, 6, 8
, but the model doesn't actually need an array to give the same values.
Upvotes: 2
Reputation: 7181
Try to read about MV in Qt here: similar question on SO, and of course, at such resources as Model/View Programming at http://qt-project.org/. Also, there are lot of interesting videos by VoidRealms, including this theme -- VoidRealms: C++ Qt 47 - Intro to model view programming.
Try to understand it in general, and in particular case -- how it is in Qt, and all questions and yours misunderstanding will disappear.
Upvotes: 1