Solved QScatterSeries was not declared in this scope?
-
My code is as follows where I am trying to instantiate a QScatterSeries in my class:
QScatterSeries* series = new QScatterSeries;
series->append(0,2);
series->append(4,10);I have included the following headers in the class:
#include "qlineseries.h"
#include <QScatterSeries>
#include <QtCharts/QScatterSeries>The documentation states to declare the header for QScatterSeries like #include <QScatterSeries>.
I have also included QT += charts in my .pro file.
I get the following 3 errors:
QScatterSeries was not declared in this scope
'series' was not declared in this scope
'QScatterSeries' does not name a type.I am new to Qt and am confused as to why the code won't recognize the header files. I had previously done a project where I used a QLineSeries and instantiated it the same way and it worked. Any help is much appreciated!
-
@engsml
Hi
Run qmake manually after adding QT += charts to .pro file
Then it should be ok.
( it will show it know the headers)
Deleting the build folder also does it. -
@mrjj Thank you for your response. I added the QT += charts to the .pro file like this:
QT += widgets
QT += chartsand ran the qmake file. The qmake file ran successfully but the same errors come up when I run it. Is there an error in how I am writing the .pro file?
Also, what is the significance of building the qmake file?
-
@engsml
Hi
And you did install QChats ?
( its extra in the installer )You seem to done it right.
And normally just running Qmake 1 time will fix it.also
does any of the
https://doc.qt.io/qt-5/qtcharts-examples.html
work ? -
@engsml Hi, Did you add
using namespace QtCharts;
at start of your code ? -
@Gojir4 This worked! Thank you so much!
-
-
@engsml
using namespace QtCharts
just means you dont have to use it in front
like
QtCharts::XXX
but can just use
XXX directly.
Im not sure why either :)But it must mean that the full type signature is
QtCharts::QScatterSeries
and that was what it complained about. -
@mrjj Very interesting. I'll keep that in mind for the future. Thank you so much again for your help!!
-
@engsml
no problem.
Its normal c++ so
its applies to anything in namespaces.