Important: Please read the Qt Code of Conduct -

Syntax Errors When Including Header (QChart Headers)

  • 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:

    this happens:

    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)

  • Lifetime Qt Champion

    did you add
    QT += charts
    to the .pro file ?

  • @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...

  • Qt Champions 2017

    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 :

    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.

  • @dheerendra yes it was like that and was very bad structure, when i included chart class first it solved.

  • Lifetime Qt Champion

    @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.

  • @SGaist can you elaborate because it's gone over my head. I was just going by:

    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?

  • Qt Champions 2019

    @6thC said in Syntax Errors When Including Header (QChart Headers):

    #include <QtCharts>

    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)?

    Anyhow, thanks, you two @jsulm @SGaist. I'm happy to have learned and this is welcome information indeed. It's filled a few gaps I never knew I had.

    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

  • Qt Champions 2019

    @6thC said in Syntax Errors When Including Header (QChart Headers):

    This documentation then is really misleading to tell people, to include everything

    Do you mean ?
    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

  • 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.

Log in to reply