QT Creator编译程序出现以下错误:
ytep_db_database.o: In function ZN16YTEP_DB_DataBaseC2Ev': ytep_db_database.cpp:11: undefined reference to
_imp___ZN12QSqlDatabaseC1Ev’
ytep_db_database.o: In function ZN16YTEP_DB_DataBaseC2E15YT_DB_TYPE_ENUMPKcS2_S2_S2_i': ytep_db_database.cpp:20: undefined reference to
_imp___ZN12QSqlDatabaseC1Ev’
ytep_db_database.cpp:20: undefined reference to _imp___ZN12QSqlDatabaseD1Ev' ytep_db_database.o: In function
ZN16YTEP_DB_DataBaseD2Ev’:
ytep_db_database.cpp:29: undefined reference to _imp___ZN12QSqlDatabaseD1Ev' ytep_db_database.o: In function
ZN16YTEP_DB_DataBase12OpenDataBaseEv’:
ytep_db_database.cpp:66: undefined reference to _imp___ZNK12QSqlDatabase7isValidEv' ytep_db_database.cpp:68: undefined reference to
_imp___ZN12QSqlDatabase5closeEv’
ytep_db_database.cpp:103: undefined reference to _imp___ZN12QSqlDatabase17defaultConnectionE' ytep_db_database.cpp:103: undefined reference to
imp___ZN12QSqlDatabase11addDatabaseERK7QStringS2’
ytep_db_database.cpp:103: undefined reference to _imp___ZN12QSqlDatabaseaSERKS_' ytep_db_database.cpp:103: undefined reference to
_imp___ZN12QSqlDatabaseD1Ev’
ytep_db_database.cpp:104: undefined reference to _imp___ZN12QSqlDatabase11setHostNameERK7QString' ytep_db_database.cpp:105: undefined reference to
_imp___ZN12QSqlDatabase11setUserNameERK7QString’
ytep_db_database.cpp:106: undefined reference to _imp___ZN12QSqlDatabase15setDatabaseNameERK7QString' ytep_db_database.cpp:107: undefined reference to
_imp___ZN12QSqlDatabase11setPasswordERK7QString’
ytep_db_database.cpp:108: undefined reference to _imp___ZN12QSqlDatabase7setPortEi' ytep_db_database.cpp:110: undefined reference to
_imp___ZN12QSqlDatabase4openEv’
ytep_db_database.cpp:103: undefined reference to _imp___ZN12QSqlDatabaseD1Ev' ytep_db_database.o: In function
ZN16YTEP_DB_DataBase7IsErrorE7QString’:
ytep_db_database.cpp:120: undefined reference to _imp___ZN9QSqlErrorC1ERK7QStringS2_NS_9ErrorTypeES2_' ytep_db_database.cpp:122: undefined reference to
_imp___ZNK12QSqlDatabase9lastErrorEv’
ytep_db_database.cpp:122: undefined reference to _imp___ZN9QSqlErrorD1Ev' ytep_db_database.cpp:123: undefined reference to
_imp___ZNK9QSqlError7isValidEv’
ytep_db_database.cpp:125: undefined reference to _imp___ZNK9QSqlError4typeEv' ytep_db_database.cpp:136: undefined reference to
_imp___ZNK9QSqlError4textEv’
ytep_db_database.cpp:137: undefined reference to _imp___ZNK9QSqlError4textEv' ytep_db_database.cpp:143: undefined reference to
_imp___ZNK9QSqlError4textEv’
ytep_db_database.cpp:144: undefined reference to _imp___ZNK9QSqlError4textEv' ytep_db_database.cpp:120: undefined reference to
_imp___ZN9QSqlErrorD1Ev’
ytep_db_database.cpp:120: undefined reference to _imp___ZN9QSqlErrorD1Ev' ytep_db_database.o: In function
ZN16YTEP_DB_DataBase8IsDBOpenEv’:
…
出现这个错误的原因,其实很简单,很多人在建立项目的时候没有加入sql环境导致,我们只需要在 .pro文件加入sql就行了:
如下所示:
QT += core gui sql
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11