Bonsoir à toutes et tous .
J'ai découvert sur le site un tutoriel Model/View qui correspond à ce que je recherche , a savoir réaliser une fenêtre avec un tableau ... Hé oui ..
Le problème est : Les explications sont en anglais et je ne comprend pas l'anglais . Les traducteurs gratuits me donnent du charabia ..... exemple int deviens international ..
Je ne comprends pas mon erreur .mymodel.h
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 #include <QAbstractTableModel> #include <QAbstractItemModel> #include <QDebug> #include <QFont> #include <QBrush> const int COLS= 3; const int ROWS= 2; class MyModel : public QAbstractTableModel { Q_OBJECT public: MyModel(QObject *parent); int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; QVariant data(const QModelIndex &index,int role = QT::DisplayRole) const; bool setdata(const QModelIndex &index,const QVariant & value, int role = Qt::EditRole); Qt::ItemFlags flags(const QModelIndex & index)const; private: QString m_gridData[ROWS][COLS]; signals: void editCompleted(const QString &); };
Les messages d'erreurs :Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 mymodel.cpp #include "mymodel.h" QVariant MyModel::headerData(int section, Qt::Orientation orientation, int role) const { if (role == Qt::DisplayRole) { if (orientation == Qt::Horizontal) { switch (section) { case 0: return QString("first"); case 1: return QString("second"); case 2: return QString("third"); } } } return QVariant(); } bool MyModel::setData(const QModelIndex & index, const QVariant & value, int role) { if (role == Qt::EditRole) { //save value from editor to member m_gridData m_gridData[index.row()][index.column()] = value.toString(); //for presentation purposes only: build and emit a joined string QString result; for(int row= 0; row < ROWS; row++) { for(int col= 0; col < COLS; col++) { result += m_gridData[row][col] + " "; } } emit editCompleted( result ); } return true; } Qt::ItemFlags MyModel::flags(const QModelIndex & /*index*/) const { return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled ; }
in file included from /MyModel/main.cpp 5
'QT' has not been declared mymodel 27
Merci d'avance .
Cordialement .