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. Old Qt code no longer viable

Old Qt code no longer viable

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 474 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    I found this video on youtube that shows how to populate a TableView component. But I can't get it to work because Qt's changed its "reserved words". If you click on that link, you'll find the code @2:00 minutes in. I'll put it here too:

    model = new QSqlTableModel(this);
    model->setTable("People");
    model->select();
    

    setTable and select are no longer parts of the equation. If anyone knows how to get this to work the way Qt wants it done nowadays, I'd appreciate you. Thanks.

    1 Reply Last reply
    0
    • 6thC6 Offline
      6thC6 Offline
      6thC
      wrote on last edited by 6thC
      #2

      According to http://doc.qt.io/qt-5/qsqltablemodel-members.html has:
      void QSqlTableModel::setTable(const QString &tableName)[virtual]
      bool QSqlTableModel::select() [virtual slot]

      http://doc.qt.io/qt-5/qsqltablemodel.html has an example with the model and TableView:

      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();
      

      That's all from the qt5.11 docu...
      [edit: add explicit request for information] perhaps best to include the actual error message / symptoms you're experiencing so others can confirm / attempt to reproduce or support. Saying there's an issue with "reserved words" ... how can anyone assist with just that context?

      1 Reply Last reply
      2
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        I don't know what I did with the code I was using. Actually, I do. I was working a tutorial, and I got lazy and didn't start a new project for the following tutorial, just altered the one I had going. And for whatever reason, I cldn't get setTable to come up for me. I just started a new tutorial and it works just fine.

        I apologize for wasting the forum's time. And thank you for yours, 6thC.

        6thC6 1 Reply Last reply
        0
        • ? A Former User

          I don't know what I did with the code I was using. Actually, I do. I was working a tutorial, and I got lazy and didn't start a new project for the following tutorial, just altered the one I had going. And for whatever reason, I cldn't get setTable to come up for me. I just started a new tutorial and it works just fine.

          I apologize for wasting the forum's time. And thank you for yours, 6thC.

          6thC6 Offline
          6thC6 Offline
          6thC
          wrote on last edited by
          #4

          @landslyde all good mate. I just don't have an an SQL engine to run up so couldn't really test, but that docu seemed to indicate either a bug or something else. Glad it's sorted!

          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