所以我有谷歌这个问题并搜索这个网站,但我发现的一切都不起作用。以下是头文件中的麻烦行:
ChartView(QChart *chart, QWidget *parent = 0);
QLineSeries *hLine;
QLineSeries *vLine;
bool isDoneDrawing;
void doneDrawing(bool newValue);
这是头文件:
#ifndef CHARTVIEW_H
#define CHARTVIEW_H
#include <QtCharts/QChartView>
#include <QtWidgets>
#include <QtCharts>
QT_CHARTS_USE_NAMESPACE
class ChartView : public QChartView
{
public:
ChartView(QChart *chart, QWidget *parent = 0);
QLineSeries *hLine;
QLineSeries *vLine;
bool isDoneDrawing;
void doneDrawing(bool newValue);
protected:
void mouseMoveEvent(QMouseEvent *event);
};
#endif
这是ccp文件:
#include <QtWidgets>
#include <QtCharts>
#include "chartview.h"
ChartView::ChartView(QChart *chart, QWidget *parent) :
QChartView(chart, parent){
isDoneDrawing = false;
hLine = new QLineSeries();
hLine->setPen(QPen(QColor(Qt::white), 0.5, Qt::DotLine));
chart->addSeries(hLine);
//this->chart()->addSeries(hLine);
vLine = new QLineSeries();
vLine->setPen(QPen(QColor(Qt::white), 0.5, Qt::DotLine));
chart->addSeries(vLine);
//this->chart()->addSeries(vLine);
setContentsMargins(0,0,0,0);
}
void ChartView::doneDrawing(bool newValue){
isDoneDrawing = newValue;
}
void ChartView::mouseMoveEvent(QMouseEvent *event){
if(isDoneDrawing){
//draw horizontal line
double y = double(event->pos().y());
if(y < this->chart()->plotArea().bottom() && y > this->chart()->plotArea().top()){
this->chart()->removeSeries(hLine);
double min = this->chart()->property("yMin").toDouble();
double max = this->chart()->property("yMax").toDouble();
//rescale y
y = (max-min)*(y-this->chart()->plotArea().top())/(this->chart()->plotArea().bottom()-this->chart()->plotArea().top())+min;
//invert y
y= (max+min)-y;
hLine->clear();
hLine->append(0,y);
hLine->append(this->chart()->plotArea().right(),y);
hLine->append(this->chart()->size().width(),y);
this->chart()->addSeries(hLine);
hLine->attachAxis(this->chart()->axisY());
hLine->attachAxis(this->chart()->axisX());
}
//draw vertical line
double x = double(event->pos().x());
if(x < this->chart()->plotArea().right() && x > this->chart()->plotArea().left()){
this->chart()->removeSeries(vLine);
double min = this->chart()->property("xMin").toDouble();
double max = this->chart()->property("xMax").toDouble();
//rescale x
x = (max-min)*(x-this->chart()->plotArea().right())/(this->chart()->plotArea().left()-this->chart()->plotArea().right())+min;
//update price info in title
QStringList data = this->chart()->property(QString::number((int)x).toUtf8()).toString().split(',');
QString title;
QString dataColor = this->chart()->series().at(0)->property(QString::number((int)x).toUtf8()).toString();
title = this->chart()->property("newTitle").toString().append("<table style='color:"+dataColor+"; font-size:10px'><tr><td width='100'>Date:<br>").append(data[0]);
title.append("</td><td width='50'>Open:<br>").append(data[3]);
title.append("</td><td width='50'>High:<br>").append(data[4]);
title.append("</td><td width='50'>Low:<br>").append(data[1]);
title.append("</td><td width='50'>Close:<br>").append(data[2]);
title.append("</td><td width='50'>High:<br>").append(data[5]);
title.append("</td><td width='50'>Low:<br>").append(data[6]);
if(data.size() > 7){
title.append("</td><td width='50'>PC:<br>").append(data[7]);
}else{
title.append("</td><td width='50'>PC:<br>");
}
title.append("</td></tr></table>");
this->chart()->setTitle(title);
//invert x
x= (max+min)-x;
vLine->clear();
vLine->append(x,this->chart()->size().height());
vLine->append(x,0);
this->chart()->addSeries(vLine);
vLine->attachAxis(this->chart()->axisY());
vLine->attachAxis(this->chart()->axisX());
}
}
}
我尝试在每个声明之前添加extern,但找不到我错过的地方';'在一条线的尽头。任何帮助都会很棒。我正在使用全新安装的Ubuntu和Qt Creator。该项目已从我之前的安装中导入。
希望这是足够的信息。关于这个错误的许多其他问题都缺乏信息,所以我希望这个问题也能解决这个问题。
以下是错误代码:
/home/bandito/programming/build-etf-ipo-new-Unnamed-Debug/chartview.o:-1:在函数
QList<QtCharts::QAbstractSeries*>::node_destruct(QList<QtCharts::QAbstractSeries*>::Node*, QList<QtCharts::QAbstractSeries*>::Node*)': /home/bandito/programming/etf-ipo-new/chartview.cpp:5: error: multiple definition of
ChartView :: ChartView(QtCharts :: QChart *,QWidget *) “ /home/bandito/programming/etf-ipo-new/chartview.cpp:5:首先在这里定义 /home/bandito/programming/build-etf-ipo-new-Unnamed-Debug/chartview.o:-1:功能QList<QtCharts::QAbstractSeries*>::node_destruct(QList<QtCharts::QAbstractSeries*>::Node*, QList<QtCharts::QAbstractSeries*>::Node*)': /home/bandito/programming/etf-ipo-new/chartview.cpp:5: error: multiple definition of
ChartView :: ChartView(QtCharts :: QChart *,QWidget *)' /home/bandito/programming/etf-ipo-new/chartview.cpp:5:首先在这里定义 /home/bandito/programming/build-etf-ipo-new-Unnamed-Debug/chartview.o:-1:功能ChartView::doneDrawing(bool)': /home/bandito/programming/etf-ipo-new/chartview.cpp:24: error: multiple definition of
ChartView :: doneDrawing(布尔)” /home/bandito/programming/etf-ipo-new/chartview.cpp:24:首先在这里定义 /home/bandito/programming/build-etf-ipo-new-Unnamed-Debug/chartview.o:-1:功能ChartView::mouseMoveEvent(QMouseEvent*)': /home/bandito/programming/etf-ipo-new/chartview.cpp:28: error: multiple definition of
ChartView :: mouseMoveEvent(QMouseEvent *)” /home/bandito/programming/etf-ipo-new/chartview.cpp:28:首先在这里定义 :-1:错误:collect2:错误:ld返回1退出状态