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. QChartView or QGraphicScene
Qt 6.11 is out! See what's new in the release blog

QChartView or QGraphicScene

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 3 Posters 11.7k Views 3 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #3

    Hi

    Did you add QT += charts to your .pro file ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    1
    • Z Offline
      Z Offline
      Zhitoune
      wrote on last edited by
      #4

      Thanks for your reply.
      Yes i did , but it still doesn't work....
      here is my .pro just in case :

      #-------------------------------------------------
      #
      # Project created by QtCreator 2017-07-27T14:27:37
      #
      #-------------------------------------------------
      
      QT       += core gui \
             charts
      
      
      greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
      
      TARGET = aoFcs
      TEMPLATE = app
      
      # The following define makes your compiler emit warnings if you use
      # any feature of Qt which as been marked as deprecated (the exact warnings
      # depend on your compiler). Please consult the documentation of the
      # deprecated API in order to know how to port your code away from it.
      DEFINES += QT_DEPRECATED_WARNINGS
      
      # You can also make your code fail to compile if you use deprecated APIs.
      # In order to do so, uncomment the following line.
      # You can also select to disable deprecated APIs only up to a certain version of Qt.
      #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
      
      
      SOURCES += main.cpp\
         tools.cpp \
         chartWidget.cpp \
         mainWindow.cpp \
         settingWidget.cpp
      
      HEADERS  += \
         tools.h \
         chartWidget.h \
         mainWindow.h \
         settingWidget.h
      
      
      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #5

        And re-ran qmake after adding the module ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          Zhitoune
          wrote on last edited by
          #6

          It still doesn't work.
          I compared qmake and make instruction of my project and a qt example that works and they are striclty the same apart from the directory adress.

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            Zhitoune
            wrote on last edited by
            #7

            So apparently declaring

            #include <QtCharts/QChartGlobal>
            

            was not enough

            I had to declare :

            #include <QtCharts/QChartGlobal>
            #include <QtCharts/QChart>
            #include <QtCharts/QChartView>
            #include <QtCharts/QLineSeries>
            #include <QtCharts/QScatterSeries>
            

            Don't ask me why it works in the examples and not in my project...
            Thanks for you help!

            JKSHJ 1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #8

              What example are you referring to ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • Z Offline
                Z Offline
                Zhitoune
                wrote on last edited by
                #9

                it was themedWidget

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #10

                  Where did you get that example ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • Z Offline
                    Z Offline
                    Zhitoune
                    wrote on last edited by
                    #11

                    in qt creator.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #12

                      Can you give the exact name please ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • Z Zhitoune

                        So apparently declaring

                        #include <QtCharts/QChartGlobal>
                        

                        was not enough

                        I had to declare :

                        #include <QtCharts/QChartGlobal>
                        #include <QtCharts/QChart>
                        #include <QtCharts/QChartView>
                        #include <QtCharts/QLineSeries>
                        #include <QtCharts/QScatterSeries>
                        

                        Don't ask me why it works in the examples and not in my project...
                        Thanks for you help!

                        JKSHJ Offline
                        JKSHJ Offline
                        JKSH
                        Moderators
                        wrote on last edited by
                        #13

                        @Zhitoune said in QChartView or QGraphicScene:

                        So apparently declaring

                        #include <QtCharts/QChartGlobal>
                        

                        was not enough

                        I had to declare :

                        #include <QtCharts/QChartGlobal>
                        #include <QtCharts/QChart>
                        #include <QtCharts/QChartView>
                        #include <QtCharts/QLineSeries>
                        #include <QtCharts/QScatterSeries>
                        

                        There are two step you should take to do this correctly.

                        First, use Forward Declarations in your header:

                        class QChart;
                        class QChartView;
                        class QLineSeries;
                        class QScatterSeries;
                        

                        You need the forward declarations because your header contains the pointers QChart*, QChartView*, QLineSeries*, and QScatterSeries*.

                        Second, include the relevant headers in your .cpp file:

                        #include <QtCharts/QChart>
                        #include <QtCharts/QChartView>
                        #include <QtCharts/QLineSeries>
                        #include <QtCharts/QScatterSeries>
                        
                        // OR, even better:
                        #include <QChart>
                        #include <QChartView>
                        #include <QLineSeries>
                        #include <QScatterSeries>
                        

                        Don't ask me why it works in the examples and not in my project...

                        One reason is because the example does not refer to QLineSeries or QScatterSeries in the header: That's why the example doesn't need to forward-declare these two classes.

                        Note that the example:

                        1. Forward-declares QChart and QChartView in the header file: https://doc.qt.io/qt-5/qtcharts-chartthemes-themewidget-h.html
                        2. #includes lots of chart-related classes in the .cpp file: https://doc.qt.io/qt-5/qtcharts-chartthemes-themewidget-cpp.html

                        Finally, you can get rid of QT_CHARTS_BEGIN_NAMESPACE and QT_CHARTS_END_NAMESPACE from your code. These macros are not strictly necessary.

                        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                        1 Reply Last reply
                        1

                        • Login

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