Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. French
  4. Insertion requête dans une table
QtWS25 Last Chance

Insertion requête dans une table

Scheduled Pinned Locked Moved Unsolved French
1 Posts 1 Posters 464 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lacombe
    wrote on 20 May 2019, 10:20 last edited by
    #1

    Bonjour,

    J'ai trouvé dans la doc l'exemple suivant où un QSTRINGLIST est utilisé comme donnée. Comment faire quand on a le résultat d'une requête (mRequete) avec le code: sqlModele = new QSqlQueryModel();
    sqlModele->setQuery(*mRequete);

    Merci de votre aide.

    Voici le code de la doc:

    paystablemodel.h

    #ifndef PAYSTABLEMODEL_H
    #define PAYSTABLEMODEL_H
    
    #include <QAbstractTableModel>
    #include <QModelIndex>
    
    class PaysTableModel : public QAbstractTableModel {
    private:
    QStringList listePays;
    public:
    PaysTableModel(const QStringList &listePays, QObject *parent = 0):QAbstractTableModel(parent)
    
    {if (listePays.count() > 0) this->listePays = listePays;}
    int rowCount(const QModelIndex &parent = QModelIndex()) const
    { return this->listePays.count(); }
    int columnCount(const QModelIndex &parent = QModelIndex()) const
    { return 2;}
    // pour insérer une (future) capitale
    QVariant data(const QModelIndex &index, int role) const {
    if (! index.isValid())
    return QVariant();
    if (((unsigned int)index.row()>=this->listePays.count())||(index.column()>= 2))
    return QVariant();
    if ((role == Qt:isplayRole)) {
    if(index.column() == 0) // la première colonne = pays
    return this->listePays.at(index.row()); // retourne le nom du pays demandé
    }
    else return QVariant();
    }
    
    };
    
    
    
    #endif // PAYSTABLEMODEL_H
    

    main.cpp

    #include <QApplication>
    #include <QStringListModel>
    #include <QTableView>
    #include <QWidget>
    #include "Paystablemodel.h"
    
    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    QWidget Widget;
    QWidget tableWidget;
    QStringList listePays;
    listePays << "France" << "Angleterre" << "Espagne" << "Italie" << "Allemagne";
    PaysTableModel *modele = new PaysTableModel(listePays);
    QTableView *vueTable = new QTableView;
    vueTable->setModel(modele);
    vueTable->show();
    return app.exec();
    }
    
    
    1 Reply Last reply
    0

    1/1

    20 May 2019, 10:20

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved