1
閱讀Qt的助理後,我使這些對象爲什麼我收到QtCreator中的未定義參考錯誤?
#include "account.h"
#include<QtSql/QSqlDatabase>
#include<QtSql/QSqlQuery>
Account::Account(QWidget *parent)
: QMainWindow(parent)
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
QSqlQuery q(db);
q.exec("CREATE TABLE my");
}
運行後,我得到這些錯誤:
error: undefined reference to `QSqlDatabase::defaultConnection'
error: undefined reference to `QSqlDatabase::addDatabase(QString const&, QString const&)'
error: undefined reference to `QSqlQuery::QSqlQuery(QSqlDatabase)'
error: undefined reference to `QSqlQuery::exec(QString const&)'
和其他錯誤有關的析構函數:
error: undefined reference to `QSqlDatabase::~QSqlDatabase()'
.........
你鏈接到適當的庫嗎? –