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
QtWS25 Last Chance

example of Qt dektop SQL

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 333 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.
  • saulosS Offline
    saulosS Offline
    saulos
    wrote on 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
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 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
      • saulosS Offline
        saulosS Offline
        saulos
        wrote on 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.
        :(

        jsulmJ 1 Reply Last reply
        0
        • saulosS saulos

          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.
          :(

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on 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
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on 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
            • saulosS Offline
              saulosS Offline
              saulos
              wrote on last edited by
              #6

              Thanks to All
              All solved :)

              1 Reply Last reply
              0

              • Login

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