Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. example of Qt dektop SQL
Forum Update on Monday, May 27th 2025

example of Qt dektop SQL

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 346 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.
  • S Offline
    S Offline
    saulos
    wrote on 2 Apr 2020, 10:05 last edited by
    #1

    Hi, I'm trying to understand how I can show/manipulate a DB table with QT, i will like to by pointed to some example.
    Just to understand I'm use to program in Visual Studio and connect to various SQL, create form with fields and grid . I was able to connect to my server (MariaDB) and do sone basic command , now I will like to replicate what I usually do in VS , like create a window with a grid that show the data from a query.
    I searched on the forum but I just find pice of code and is difficult to put all together, so if any one can point me to an example it will be wonderful :)
    Thanks

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 2 Apr 2020, 10:30 last edited by
      #2

      You should take a look at QSqlTableModel and the examples linked in the documentation there.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • S Offline
        S Offline
        saulos
        wrote on 3 Apr 2020, 08:13 last edited by
        #3

        Thanks, I try also the example, very cool .
        But still I don't understand how to display the QsqlTableModel on a UI.
        I just create a simple UI
        QMainWindow
        QWidget

        Then I don't know how to display the tablemodel.
        :(

        J 1 Reply Last reply 3 Apr 2020, 09:23
        0
        • S saulos
          3 Apr 2020, 08:13

          Thanks, I try also the example, very cool .
          But still I don't understand how to display the QsqlTableModel on a UI.
          I just create a simple UI
          QMainWindow
          QWidget

          Then I don't know how to display the tablemodel.
          :(

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 3 Apr 2020, 09:23 last edited by
          #4

          @saulos The link provided by @Christian-Ehrlicher shows how:

           QSqlTableModel *model = new QSqlTableModel(parentObject, database);
           model->setTable("employee");
           model->setEditStrategy(QSqlTableModel::OnManualSubmit);
           model->select();
           model->setHeaderData(0, Qt::Horizontal, tr("Name"));
           model->setHeaderData(1, Qt::Horizontal, tr("Salary"));
          
           QTableView *view = new QTableView;
           view->setModel(model);
           view->hideColumn(0); // don't show the ID
           view->show();
          

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 3 Apr 2020, 13:06 last edited by
            #5

            Hi
            Qt models work with views
            For DB models often TableView is used.
            https://doc.qt.io/qt-5/model-view-programming.html

            alt text

            you have to set the model from code.

            1 Reply Last reply
            1
            • S Offline
              S Offline
              saulos
              wrote on 3 Apr 2020, 15:34 last edited by
              #6

              Thanks to All
              All solved :)

              1 Reply Last reply
              0

              1/6

              2 Apr 2020, 10:05

              • Login

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