我正在制作一个程序,根据用户输入计算一堆值,并且应该输出这些输入的条形图。最初我的值存储在QVectors中,而QBarSet类append()
函数仅适用于QLists。将所有QVectors更改为QLists并修复append()
错误后,我遇到了58个错误,它们都是以下变体:
error: undefined reference to `_imp___ZN8QtCharts*'
asterik表示许多不同的错误。
#include "sixthpage.h"
#include "ui_sixthpage.h"
#include "fifthpage.h"
#include "thirdpage.h"
#include "fourthpage.h"
#include <QtWidgets/QApplication>
#include <QtWidgets/QMainWindow>
#include <QtCharts/QChartView>
#include <QtCharts/QBarSeries>
#include <QtCharts/QBarSet>
#include <QtCharts/QLegend>
#include <QtCharts/QBarCategoryAxis>
#include <QList>
using namespace QtCharts;
sixthpage::sixthpage(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::sixthpage)
{
ui->setupUi(this);
showMaximized();
FifthPage *fifthpage = new FifthPage();
ThirdPage *thirdpage = new ThirdPage();
FourthPage *fourthpage = new FourthPage();
QObject::connect(thirdpage,SIGNAL(economicData(QList<double>,QList<double>)),this, SLOT(showEconomicGraph(QList<double> normalizedKPI,QList<double> maxNormalizedKPI)));
QObject::connect(fourthpage,SIGNAL(enviornmentlaData(QList<double>,QList<double>)),this, SLOT(showEnviornmentalGraph(QList<double> normalizedKPI,QList<double> maxNormalizedKPI)));
QObject::connect(fifthpage,SIGNAL(socialData(QList<double>,QList<double>)),this, SLOT(showSocialGraph(QList<double> normalizedKPI,QList<double> maxNormalizedKPI)));
}
sixthpage::~sixthpage()
{
delete ui;
}
void sixthpage::on_showGraph_clicked(QList<double> normalizedKPI, QList<double> maxNormalizedKPI)
{
if(ui->radioButton->isCheckable())
{
showEconomicGraph(normalizedKPI, maxNormalizedKPI);
}
if(ui->radioButton_2->isCheckable())
{
showEnviornmentalGraph(normalizedKPI, maxNormalizedKPI);
}
if(ui->radioButton_3->isCheckable())
{
showSocialGraph(normalizedKPI, maxNormalizedKPI);
}
}
void sixthpage::showEconomicGraph(QList<double> normalizedKPI, QList<double> maxNormalizedKPI){
//int size = normalizedKPI.length();
QBarSet *set0 = new QBarSet("Normalized KPI Achievement");
QBarSet *set1 = new QBarSet("Max. Normalized KPI Achievement");
set0->append(normalizedKPI);
set1->append(maxNormalizedKPI);
QBarSeries *series = new QBarSeries();
series->append(set0);
series->append(set1);
QChart *chart = new QChart();
chart->addSeries(series);
chart->setTitle("Economic Sustainability");
chart->setAnimationOptions(QChart::SeriesAnimations);
QStringList categories;
categories << "X1" << "X2" << "X3" << "X4" << "X5" << "X6" << "X7" << "X8" << "X9" << "X10" << "X11" << "X12" << "X13" << "X14";
QBarCategoryAxis *axis = new QBarCategoryAxis();
axis->append(categories);
chart->createDefaultAxes();
chart->setAxisX(axis, series);
chart->legend()->setVisible(true);
chart->legend()->setAlignment(Qt::AlignBottom);
QChartView *chartView = new QChartView(chart);
chartView->setRenderHint(QPainter::Antialiasing);
}
void sixthpage::showEnviornmentalGraph(QList<double> normalizedKPI, QList<double> maxNormalizedKPI){
// int size = normalizedKPI.length();
QBarSet *set0 = new QBarSet("Normalized KPI Achievement");
QBarSet *set1 = new QBarSet("Max. Normalized KPI Achievement");
set0->append(normalizedKPI);
set1->append(maxNormalizedKPI);
QBarSeries *series = new QBarSeries();
series->append(set0);
series->append(set1);
QChart *chart = new QChart();
chart->addSeries(series);
chart->setTitle("Enviornmental Sustainability");
chart->setAnimationOptions(QChart::SeriesAnimations);
QStringList categories;
categories << "X15" << "X16" << "X17" << "X18" << "X19" << "X20" << "X21" << "X22" << "X23" << "X24" << "X25";
QBarCategoryAxis *axis = new QBarCategoryAxis();
axis->append(categories);
chart->createDefaultAxes();
chart->setAxisX(axis, series);
chart->legend()->setVisible(true);
chart->legend()->setAlignment(Qt::AlignBottom);
QChartView *chartView = new QChartView(chart);
chartView->setRenderHint(QPainter::Antialiasing);
}
void sixthpage::showSocialGraph(QList<double> normalizedKPI, QList<double> maxNormalizedKPI){
// int size = normalizedKPI.length();
QBarSet *set0 = new QBarSet("Normalized KPI Achievement");
QBarSet *set1 = new QBarSet("Max. Normalized KPI Achievement");
set0->append(normalizedKPI);
set1->append(maxNormalizedKPI);
QBarSeries *series = new QBarSeries();
series->append(set0);
series->append(set1);
QChart *chart = new QChart();
chart->addSeries(series);
chart->setTitle("Social Sustainability");
chart->setAnimationOptions(QChart::SeriesAnimations);
QStringList categories;
categories << "X26" << "X27" << "X28" << "X29" << "X30" << "X31" << "X32" << "X33" << "X34" << "X35" << "X36" << "X37";
QBarCategoryAxis *axis = new QBarCategoryAxis();
axis->append(categories);
chart->createDefaultAxes();
chart->setAxisX(axis, series);
chart->legend()->setVisible(true);
chart->legend()->setAlignment(Qt::AlignBottom);
QChartView *chartView = new QChartView(chart);
chartView->setRenderHint(QPainter::Antialiasing);
}
如果有人能告诉我如何摆脱未定义的参考错误,我将非常感激。也可以随意指出任何其他可见的错误。我对QT很陌生,所以我很难完成任务。
修改
此link被标记为可能重复,但它解释了链接问题的一般错误,我已经理解了。我想要的是有人解释我的QtCharts特有的错误是如何解决的。我已经添加了文档显示的所有必要文件。