錯誤訊息:'QSqlTableModel' was not declared in this scope
加入對應標頭檔:
#include <QtSql/QSqlTableModel>
錯誤訊息:'QTableView' was not declared in this scope
加入標頭檔:
#include <QTableView>
錯誤訊息:undefined reference to `QSqlDatabase::~QSqlDatabase()'
這是連結器錯誤,表示缺少 SQL 模組庫。
在 .pro 專案檔加入:
QT += sql
執行 qmake 重新生成 Makefile 後重新建置即可。
| 錯誤類型 | 階段 | 原因 | 解決方向 |
|---|---|---|---|
| not declared in this scope | 編譯期 | 缺少標頭檔宣告 | 加入 #include |
| undefined reference | 連結期 | 缺少庫檔連結 | 修改 .pro 加入模組 |
<ModuleName/ClassName> 路徑下