Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
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;
I have included the following headers in the class:
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!
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 += charts
and 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?
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.
does any of the
Gojir4 last edited by
@engsml Hi, Did you add
using namespace QtCharts;at start of your code ?
@Gojir4 This worked! Thank you so much!
@mrjj Yes the examples worked when I ran them on my Qt Creator IDE. That was why I was confused because I was copying what their code had, but mine wasn't working even though the examples would run perfectly. @Gojir4 's solution worked for me though, but I am really not sure why!
using namespace QtCharts
just means you dont have to use it in front
but can just use
Im not sure why either :)
But it must mean that the full type signature is
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!!
Its normal c++ so
its applies to anything in namespaces.