Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Syntax Errors When Including Header (QChart Headers)
R_Irudezu last edited by R_Irudezu
This is a weird error, i think it is concerned with namespaces but i don't know how to solve that.
Problem is, when i include that line:
all my functions are in correct syntax but all of them throws syntax error when i include that line.
What might be causes that?
Edit: the header can be included in other project with no errors. (In a clean project, i mean empty ui project)
did you add
QT += charts
to the .pro file ?
R_Irudezu last edited by
@mrjj yes i added already, if i didn't the error would be shown with first QChart include, but it happens when i add QValueAxis.
I think it might be header including order error but i can't find it. Or do i think wrong, maybe something different causes that...
I think you may be doing something like including one.h in two.h and two.h in one.h file. Just check this round about.
Have you seen : https://doc.qt.io/qt-5.11/qtcharts-index.html
Have you included QtCharts?
Instead of that macro, I noticed a while back all the recent examples instead now use:
#include <QtCharts> using namespace QtCharts;
Just ideas, without code to reproduce we can only hit and miss assist. Not very efficient methods to troubleshoot.
R_Irudezu last edited by
@dheerendra yes it was like that and was very bad structure, when i included chart class first it solved.
@6thC Don't use module wide includes. It might be fine for short examples and quick tests but it pulls in everything from said module which slows down compilation. Always only include what you use.
6thC last edited by 6thC
If you intend to use Qt Charts C++ classes in your application, use the following include and using directives: #include <QtCharts> using namespace QtCharts;
I'm the only dev here and so I have to learn all myself from reference material and examples.
I only use c++14, I don't think that even has modules?
QtChart is called "module" in Qt. C++ does not have such a concept, so it's just a notation in Qt.
The problem with such includes is that it will include all header files from QtCharts. So, first preprocessor will need to handle all these includes and then compiler will get a lot more code to compile. This will slow down the build process as @SGaist said.
You should always include only what is really needed (not only when using Qt).
Oh right, yes, I agree with only including what you need!
This documentation then is really misleading to tell people, to include everything, I can't imagine this ever being a good idea as I very much love c++ for the use only what you need mentality.
I just didn't know if Qt was gearing up for c++ modules already... I suspected it was just a terminology thing. I also suspected that if the bible says this is how you get charts that this thing is necessary.
I've read both:
Qt 5.12 > All C++ APIs per Module
Qt 5.12 > All Modules
before, just never actually clicked. I think having team members and speaking aloud about things would have caught this gap sooner.
My qmake currently has:
QT += qml quick widgets charts network quickcontrols2 svg
I suspect this will remain the same, like, I can't narrow this down any hey (best I can tell I cannot)?
This is pretty exciting to hear, I'm just plotting LineSeries values over time now - I'm probably going to be able to remove this now and go for:
#include <QChart> #include <QChartView> #include <QLineSeries> #include <QDateTimeAxis> #include <QValueAxis>
Now I'm going to look for other <Qt includes and see if I've done this everywhere... it's already fast but to get leaner again is very welcome.
Sorry to feed you incorrect info and the little unintentional hijack @R_Irudezu
This documentation then is really misleading to tell people, to include everything
Do you mean https://doc.qt.io/qt-5.11/qtcharts-index.html ?
This is the starting point for the module in the documentation. If you go to a class in this module you will see that only the exact header is suggested, see for example https://doc.qt.io/qt-5.11/qbarset.html
Yes that's the page I linked earlier.
Yes, I'm aware of that, that's how I normally use reference material. It's very nice to have. Reading this page when I started out seemed to indicate to me that I also needed to do this, which I do not.
It's ok, I've said my piece. I've learned, I was just trying to assist. I'm happy to leave it here.