2

阅读 Qt Assistant 后,我​​制作了这些对象

#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()'
.........
4

1 回答 1

16

将此添加到您的专业文件中:

QT += sql
于 2013-05-17T13:55:30.777 回答