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. QTableView first time use

QTableView first time use

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 245 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
    Seabird
    wrote on last edited by
    #1

    Trying to diplay a SQLite table into my application was a struggle but I got there. I can even edit every entry in real time.

    The only thing that does not seem possible is to add a new entry in this form, or to filter columns from displaying.

        QSqlDatabase mydb=QSqlDatabase::addDatabase("QSQLITE");
        mydb.setDatabaseName("mydatabase.db");
    
            QSqlTableModel *modal = new QSqlTableModel;
            modal->setTable("MyFirstTable");
                    modal->select();
                    ui->tableView_MyFirstTableView->setModel(modal);
    

    Another problem I am having in my learning curve is that I wouold like to seperate this function into it's own class (call it MyTableView()) so I can call it taking the table as a variable and the ui->window as a output:

    MyTableView(MyfirstTable,MyFirstTableView)
    

    So I created a new Class (cpp/h) and cut my code in there but that crashed the build.

    JonBJ 1 Reply Last reply
    0
    • S Seabird

      Trying to diplay a SQLite table into my application was a struggle but I got there. I can even edit every entry in real time.

      The only thing that does not seem possible is to add a new entry in this form, or to filter columns from displaying.

          QSqlDatabase mydb=QSqlDatabase::addDatabase("QSQLITE");
          mydb.setDatabaseName("mydatabase.db");
      
              QSqlTableModel *modal = new QSqlTableModel;
              modal->setTable("MyFirstTable");
                      modal->select();
                      ui->tableView_MyFirstTableView->setModel(modal);
      

      Another problem I am having in my learning curve is that I wouold like to seperate this function into it's own class (call it MyTableView()) so I can call it taking the table as a variable and the ui->window as a output:

      MyTableView(MyfirstTable,MyFirstTableView)
      

      So I created a new Class (cpp/h) and cut my code in there but that crashed the build.

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #2

      @Seabird said in QTableView first time use:

      The only thing that does not seem possible is to add a new entry in this form

      You will need to add something to the QTableView, or a separate widget, for "Add new Row". The table view itself only has a way to edit existing rows, or to delete them if you add e.g. a "Delete" button in a column against each row, or a checkbox against each one and a "Delete" all checked rows button.

      or to filter columns from displaying

      QTableView allows you hide individual columns if you wish. A QAbstractProxyModel interposed between your model table and the table view can also be used for e.g. hiding either columns or rows. The convenience proxy model QSortFilterProxyModel builds on that to offer both/either sorting and filtering, but note that is to sort/filter rows, not columns.

      So I created a new Class (cpp/h) and cut my code in there but that crashed the build.

      Nobody can answer that without knowing the code and where it crashed.

      1 Reply Last reply
      1

      • Login

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