QT5中的TableView不显示MYSQL数据,仅显示空行 [英] TableView in QT5 doesn't show MYSQL Data, just empty rows are shown

查看:581
本文介绍了QT5中的TableView不显示MYSQL数据,仅显示空行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过显示屏幕快照向您展示我的问题.对我来说,这似乎更容易.

I am showing you my problem by showing a screen shot. This seems easier to me.

我的表在我的程序中为空,但是它具有正确的列数,如果我在sql工作台中添加更多的列,它将获得更多的行,但其中没有任何显示. 这是我的源代码:

My Table is empty in my program, but it has the right amount of columns and if I add more columns in my sql workbench it will get more rows, but nothing is displayed in them. Here is my Source Code:

void adminUserData::on_pushButton_Load_clicked()
{
    // This Object is for connecting to my Database (it works).
    Datenbank db;
    db.connData();

    QSqlQueryModel* model = new QSqlQueryModel();

    QSqlQuery* qry = new QSqlQuery(db.db);

    qry->prepare("SELECT * FROM worker");

    qry->exec();
    model->setQuery(*qry);

    ui->tableView->setModel(modal);

    qDebug() << model->rowCount();
    db.discData();
}

我不知道怎么了.这是工作台中我的数据库的屏幕截图: 谢谢你们对我的帮助. 最好的问候

I have no clue whats wrong. Here is a screen shot of my database in the workbench: Thank you guys for helping me. best regards

推荐答案

不应"ui-> tableView-> setModel(modal);"是"ui-> tableView-> setModel(mod e l);"?

Shouldn't "ui->tableView->setModel(modal);" be "ui->tableView->setModel(model);"?

这篇关于QT5中的TableView不显示MYSQL数据,仅显示空行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆