Qt World Summit: Register Today!

Old Qt code no longer viable

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

    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.

  • 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->setHeaderData(0, Qt::Horizontal, tr("Name"));
        model->setHeaderData(1, Qt::Horizontal, tr("Salary"));
        QTableView *view = new QTableView;
        view->hideColumn(0); // don't show the ID

    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?

  • 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.

  • @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!

Log in to reply