Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. French
  4. L'utilisation de QslQueryModel sur c++ et Quick
Forum Updated to NodeBB v4.3 + New Features

L'utilisation de QslQueryModel sur c++ et Quick

Scheduled Pinned Locked Moved Solved French
2 Posts 2 Posters 535 Views 1 Watching
  • 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.
  • FortigaF Offline
    FortigaF Offline
    Fortiga
    wrote on last edited by
    #1

    Bonsoir tout le monde ❤️
    Enfaite j'essaie d'afficher des données depuis la base données MySQL
    Code source
    Main.qml

    Frame{
                              Layout.fillHeight: true
                              Layout.fillWidth: true
                              Flickable
                              {
                                  anchors.fill: parent
    
                                  Text {
                                      id: text1
                                      anchors.verticalCenterOffset: 20
                                      anchors.horizontalCenter: parent.horizontalCenter
                                      text: qsTr("Top les enquêtes ouvertes Récemment")
                                      font.pixelSize: 18
                                      font.bold: true
                                      }
                                          ListView {
                                              id: list_view1
                                             anchors.fill: parent
                                             anchors.topMargin: 20
                                              delegate: DataItemDelegate {}
                                              model: sqlQuery
                                          }
                                      }
                                  }
    

    DataItemDelegatr.qml

    Item {
    
        id: delegate
        //anchors.fill: parent
        width: delegate.ListView.view.width;
       height: 300
        clip: true
        anchors.margins: 4
        RowLayout {
            anchors.margins: 4
            anchors.fill: parent
            spacing: 4;
            Text {
                text: sqlQuery.nom("grade", 0)
                width: 150
            }
            Text {
                text: sqlQuery.nom("nom", 0)
                width: 150;
            }
            Text {
                text: sqlQuery.nom("service", 0)
                width: 50;
            }
        }
    }
    

    La fonction qui me permet de récupérer le donnée

    QString SqlQueryModel::nom(QString name, int index)
    {
         QSqlQueryModel model;
         model.setQuery(QString("SELECT * FROM piédestal"));
         return model.data(model.index(0, 0)).toString();
    }
    

    Petite problème j'arrive pas a récupérer tous les lignes ou tous les textes enregistrés sur la base de données

    Juste pour aller de l'avant et apprendre des choses, lorsque vous voulez devenir une légende, cela ne se fait pas du jour au lendemain.

    SGaistS 1 Reply Last reply
    0
    • FortigaF Fortiga

      Bonsoir tout le monde ❤️
      Enfaite j'essaie d'afficher des données depuis la base données MySQL
      Code source
      Main.qml

      Frame{
                                Layout.fillHeight: true
                                Layout.fillWidth: true
                                Flickable
                                {
                                    anchors.fill: parent
      
                                    Text {
                                        id: text1
                                        anchors.verticalCenterOffset: 20
                                        anchors.horizontalCenter: parent.horizontalCenter
                                        text: qsTr("Top les enquêtes ouvertes Récemment")
                                        font.pixelSize: 18
                                        font.bold: true
                                        }
                                            ListView {
                                                id: list_view1
                                               anchors.fill: parent
                                               anchors.topMargin: 20
                                                delegate: DataItemDelegate {}
                                                model: sqlQuery
                                            }
                                        }
                                    }
      

      DataItemDelegatr.qml

      Item {
      
          id: delegate
          //anchors.fill: parent
          width: delegate.ListView.view.width;
         height: 300
          clip: true
          anchors.margins: 4
          RowLayout {
              anchors.margins: 4
              anchors.fill: parent
              spacing: 4;
              Text {
                  text: sqlQuery.nom("grade", 0)
                  width: 150
              }
              Text {
                  text: sqlQuery.nom("nom", 0)
                  width: 150;
              }
              Text {
                  text: sqlQuery.nom("service", 0)
                  width: 50;
              }
          }
      }
      

      La fonction qui me permet de récupérer le donnée

      QString SqlQueryModel::nom(QString name, int index)
      {
           QSqlQueryModel model;
           model.setQuery(QString("SELECT * FROM piédestal"));
           return model.data(model.index(0, 0)).toString();
      }
      

      Petite problème j'arrive pas a récupérer tous les lignes ou tous les textes enregistrés sur la base de données

      SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Bonsoir,

      C'est normal, la method retourne toujours le même index de la même requête.

      Cet article wiki démontre comment utiliser QSqlTableModel avec QML.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • FortigaF Fortiga has marked this topic as solved on

      • Login

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