Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QScatterSeries was not declared in this scope?
Qt 6.11 is out! See what's new in the release blog

QScatterSeries was not declared in this scope?

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 3 Posters 4.7k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    engsml
    wrote on last edited by
    #1

    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!

    mrjjM 1 Reply Last reply
    0
    • E engsml

      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!

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

      E 1 Reply Last reply
      3
      • mrjjM mrjj

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

        E Offline
        E Offline
        engsml
        wrote on last edited by
        #3

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

        mrjjM Gojir4G 2 Replies Last reply
        0
        • E engsml

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

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

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

          E 1 Reply Last reply
          1
          • E engsml

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

            Gojir4G Offline
            Gojir4G Offline
            Gojir4
            wrote on last edited by
            #5

            @engsml Hi, Did you add using namespace QtCharts; at start of your code ?

            E 1 Reply Last reply
            1
            • Gojir4G Gojir4

              @engsml Hi, Did you add using namespace QtCharts; at start of your code ?

              E Offline
              E Offline
              engsml
              wrote on last edited by
              #6

              @Gojir4 This worked! Thank you so much!

              1 Reply Last reply
              0
              • mrjjM mrjj

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

                E Offline
                E Offline
                engsml
                wrote on last edited by
                #7

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

                mrjjM 1 Reply Last reply
                0
                • E engsml

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

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

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

                  E 1 Reply Last reply
                  0
                  • mrjjM mrjj

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

                    E Offline
                    E Offline
                    engsml
                    wrote on last edited by
                    #9

                    @mrjj Very interesting. I'll keep that in mind for the future. Thank you so much again for your help!!

                    mrjjM 1 Reply Last reply
                    0
                    • E engsml

                      @mrjj Very interesting. I'll keep that in mind for the future. Thank you so much again for your help!!

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @engsml
                      no problem.
                      Its normal c++ so
                      its applies to anything in namespaces.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved