我肯定我只是在我原来的课堂上遗漏了一些东西(会议视图),但是我不能把我的头脑完全集中在缺少的东西上。当我试图构建包含会议视图类的tst_conferencepage.cpp文件时,当我试图实例化一个类型为conferenceview的对象时,会收到一条有关在架构x86_64中找不到的符号的错误消息。
会议视图.h:
#ifndef CONFERENCEVIEW_H
#define CONFERENCEVIEW_H
#include "constants.h"
class conferenceView
{
QString conference; // Holds the current conference selected by the fan
QString division; // Holds the current division selected by the fan
public:
conferenceView(); // Default Constructor
void setConference(QString); // Sets the current conference of the fan
QString getConference(); // Returns the current conference of the fan
void setDivision(QString); // Sets the current division of the fan
QString getDivision(); // Gets the current division of the fan
QSqlQuery queryConference(QString); // Returns a query for the teams in a specified conference
QSqlQuery queryDivision(QString); // Returns a query for the teams in a specified conference
QSqlQueryModel* populateView(QString, int); // Returns a QSqlQueryModel index to display the queried data to the table view
};
#endif // CONFERENCEVIEW_Hconferenceview.cpp:
#include "conferenceview.h"
conferenceView::conferenceView()
{
this->conference = "";
this->division = "";
}
// Assigns conference to passed in QString
void conferenceView::setConference(QString conference) { this->conference = conference; }
// Returns conference
QString conferenceView::getConference() { return this->conference; };
// Assigns division to passed in QString
void conferenceView::setDivision(QString division) { this->division = division; }
// Returns division
QString conferenceView::getDivision() { return this->division; }
QSqlQuery conferenceView::queryConference(QString conference)
{
this->setConference(conference); // Sets current conference
// Queries database for team names by conference order by team name
QSqlQuery q;
q.prepare("SELECT TeamName "
"FROM TeamInfo "
"WHERE Conference = :conf "
"ORDER BY TeamName");
q.bindValue(":conf", conference);
q.exec();
return q;
}
QSqlQuery conferenceView::queryDivision(QString division)
{
// Sets current division
if( this->conference == "American Football Conference")
this->setDivision(division.prepend("AFC "));
else
this->setDivision(division.prepend("NFC "));
// Queries database for team names by division order by team name
QSqlQuery q;
q.prepare("SELECT TeamName "
"FROM TeamInfo "
"WHERE Division = :div "
"ORDER BY TeamName");
q.bindValue(":div", division);
q.exec();
return q;
}
QSqlQueryModel* conferenceView::populateView(QString str, int id)
{
QSqlQueryModel* qModel = new QSqlQueryModel;
// if id == 0, sets the qModel to the conference teams
if(id == 0)
{
this->setConference(str);
qModel->setQuery(this->queryConference(this->getConference()));
}
// if id == 1, sets the qModel to the division teams
else
{
this->setDivision(str);
qModel->setQuery(this->queryDivision(this->getDivision()));
}
// Sets the header title of the table view
qModel->setHeaderData(0, Qt::Horizontal, QObject::tr("Team Name"));
return qModel;
}tst_conferencepage.cpp:
#include <QtTest>
#include "../NFL_Teams_App/conferenceview.h"
class ConferencePage : public QObject
{
Q_OBJECT
QVector<QString> AFC;
public:
ConferencePage();
private slots:
void testAFCConference();
};
ConferencePage::ConferencePage()
{
this->AFC = {"Baltimore Ravens", "Buffalo Bills", "Cincinnati Bengals",
"Cleveland Browns", "Denver Broncos", "Houston Texans",
"Indianapolis Colts", "Jacksonville Jaguars", "Kansas City Chiefs",
"Los Angeles Chargers", "Miami Dolphins", "New England Patriots",
"New York Jets", "Oakland Raiders", "Pittsburgh Steelers", "Tennessee Titans"};
}
void ConferencePage::testAFCConference()
{conferenceView c; QSqlQuery query = c.queryConference("American Football Conference"); int index = 0; while(query.next()) QVERIFY(this->AFC.at(index) == query.value(index));
}ConferencePage::testAFCConference()中的阻塞代码是我实例化conferenceView类型对象的地方,错误来源于。
UnitTests.pro:
QT += core testlib sql
QT -= gui
TARGET = UnitTests
CONFIG += qt console warn_on depend_includepath testcase
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += \
tst_conferencepage.cpp项目继承人:

完全错误消息:
架构x86_64的未定义符号: "conferenceView::queryConference(QString)",引用于: ConferencePage::testAFCConference()在tst_conferencepage.o中参考资料::ConferencePage::testAFCConference() in tst_conferencepage.o ld:符号(S)未找到用于体系结构的x86_64 clang: x86_64: linker命令与退出代码1(使用-v查看调用) make1:* UnitTests错误1 make:* step Make_first Error 2 01:21:30:进程"/usr/bin/make“与代码2一起退出。在执行步骤"Make”时生成/部署项目NFLTeamsProject (kit:桌面Qt 5.11.2 clang 64bit)时出错
如有任何帮助,敬请见谅!
发布于 2018-11-12 09:47:46
您在您的conferenceview.cpp文件中缺少了conferenceview.h和conferenceview.h,所以链接器不知道您的测试应该从什么构建。您的.pro文件应该如下所示:
QT += core testlib sql
QT -= gui
TARGET = UnitTests
CONFIG += qt console warn_on depend_includepath testcase
CONFIG -= app_bundle
TEMPLATE = app
VPATH = "../NFL_Teams_App"
SOURCES += \
tst_conferencepage.cpp \
conferenceview.cpp
HEADERS += \
conferenceview.hhttps://stackoverflow.com/questions/53258694
复制相似问题