Results 1 to 5 of 5

Thread: Qt Charts, PieChart setting up

  1. #1
    Join Date
    Nov 2016
    Location
    Poland
    Posts
    18
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Question Qt Charts, PieChart setting up

    Hello everyone

    I want to start creating charts in Qt 5 with C++ (pie chart, bar graph etc.). I have problems with setting thinks up.
    I visited the website: http://doc.qt.io/qt-5/qtcharts-index.html
    They wrote:

    1. To import Qt Charts QML types, add the following import statement to your .qml file :
    Qt Code:
    1. import QtCharts 2.0
    To copy to clipboard, switch view to plain text mode 
    So, where is that .qml file? Where I should write it? I need to make it new?

    2. If you intend to use Qt Charts C++ classes in your application, use the following include and using directives:
    Qt Code:
    1. #include <QtCharts>
    2. using namespace QtCharts;
    To copy to clipboard, switch view to plain text mode 
    That part should go to header (.h) ?

    3. To link against the Qt Charts module, add this line to your qmake project file:
    Qt Code:
    1. QT += charts
    To copy to clipboard, switch view to plain text mode 
    If I understand that good, this should go to .pro file?

    Here is example of PieChart: http://doc.qt.io/qt-5/qtcharts-piechart-example.html
    There are 2 files: piechart/main.cpp and piechart/piechart.pro

    Can you write me very precisely where and how add this statements from the beginning of my post (1,2 and 3).
    I want to rewrite this PieChart example to my project to learn how it's works. When I created the project, a have the following files:
    - mainwindow.cpp
    - mainwindow.h
    - mainwindow.ui
    - PieChartTest.pro
    - PieChartTest.pro.user

    Should I create something more?
    Thank you for help!

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt Charts, PieChart setting up

    Quote Originally Posted by time View Post
    1. To import Qt Charts QML types, add the following import statement to your .qml file :
    Qt Code:
    1. import QtCharts 2.0
    To copy to clipboard, switch view to plain text mode 
    So, where is that .qml file? Where I should write it? I need to make it new?
    Well, the QML file you want to use that in.

    The QML engine needs to know which modules to look into when you are using element types in your QML code.

    Quote Originally Posted by time View Post
    2. If you intend to use Qt Charts C++ classes in your application, use the following include and using directives:
    Qt Code:
    1. #include <QtCharts>
    2. using namespace QtCharts;
    To copy to clipboard, switch view to plain text mode 
    That part should go to header (.h) ?
    It is very uncommon to put a "using namespace" clause into a header.
    If you don't need any of the classes as non-pointer/non-reference objects then a simple forward declaration should do and the include could be solely in your cpp file.

    Quote Originally Posted by time View Post
    3. To link against the Qt Charts module, add this line to your qmake project file:
    Qt Code:
    1. QT += charts
    To copy to clipboard, switch view to plain text mode 
    If I understand that good, this should go to .pro file?
    Yes, the .pro file is the qmake project file mentioned above.

    Quote Originally Posted by time View Post
    Can you write me very precisely where and how add this statements from the beginning of my post (1,2 and 3).
    I want to rewrite this PieChart example to my project to learn how it's works. When I created the project, a have the following files:
    - mainwindow.cpp
    - mainwindow.h
    - mainwindow.ui
    - PieChartTest.pro
    - PieChartTest.pro.user
    Since this is not a QtQuick application you don't need (1).
    (3) should be obvious, (2) would likely be in mainwindow.cpp

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    time (15th November 2016)

  4. #3
    Join Date
    Nov 2016
    Location
    Poland
    Posts
    18
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt Charts, PieChart setting up

    Hi, thank you for your answer anda_skoa
    So I did what you write. But when I adding
    Qt Code:
    1. #include <QtCharts>
    2. using namespace QtCharts;
    To copy to clipboard, switch view to plain text mode 
    to mainwindow.cpp I have an error C1083: cannot open include file 'QtCharts': No such file or directory and in General Messages Project ERROR: Unknown module(s) in QT: charts and it points to line where is #include <QtCharts>
    So I need some more files to my project? I don't get it...

    To be clear I will add the code, maybe I am doing something wrong what is obvious?

    Here I am adding point(3) the QT += charts
    Qt Code:
    1. QT += core gui charts
    2.  
    3. greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    4.  
    5. TARGET = PieChartTest
    6. TEMPLATE = app
    7.  
    8.  
    9. SOURCES += main.cpp\
    10. mainwindow.cpp
    11.  
    12. HEADERS += mainwindow.h
    13.  
    14. FORMS += mainwindow.ui
    To copy to clipboard, switch view to plain text mode 

    Here is mainwindow.cpp where is an error with #include <QtCharts>

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. #include <QtCharts> //error C1083 here
    5. using namespace QtCharts;
    6.  
    7. MainWindow::MainWindow(QWidget *parent) :
    8. QMainWindow(parent),
    9. ui(new Ui::MainWindow)
    10. {
    11. ui->setupUi(this);
    12. }
    13.  
    14. MainWindow::~MainWindow()
    15. {
    16. delete ui;
    17. }
    To copy to clipboard, switch view to plain text mode 

    It seems that I don't have a library connected with QtCharts. Should I download something additional?
    EDIT: I use Open Source Licence for students if it is important

  5. #4
    Join Date
    May 2011
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Qt Charts, PieChart setting up

    You have to use the QT Maintenance Tool to download Charts for 5.7+.
    --Sam

  6. The following user says thank you to scgrant327 for this useful post:

    time (15th November 2016)

  7. #5
    Join Date
    Nov 2016
    Location
    Poland
    Posts
    18
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt Charts, PieChart setting up

    Quote Originally Posted by scgrant327 View Post
    You have to use the QT Maintenance Tool to download Charts for 5.7+.
    --Sam
    Yeap, that's right. It helped, thank you very much.
    So, for next generation , how to solve this problem in few steps:

    1. Go to Qt Maintenance Tool (it is in the folder where Qt is install)
    2. Run it
    3. Choose Add components
    4. Expand list for you version which you have installed. Charts are available from Qt 5.7 (correct me if I'm wrong)
    5. Choose QtCharts (I also choosed Qt Data Visualisation)
    6. Click next
    7. Restart your Qt program
    8. Click Build -> Run qmake

    Now it should work

Similar Threads

  1. How to interaction on Charts in QML?
    By tanthinh1510 in forum Qt Quick
    Replies: 1
    Last Post: 10th February 2016, 05:35
  2. Replies: 21
    Last Post: 8th December 2011, 02:18
  3. Charts in Qt!!
    By rachana in forum Qt Programming
    Replies: 3
    Last Post: 6th May 2011, 06:10
  4. Help with Bar charts
    By romeo in forum Qwt
    Replies: 0
    Last Post: 30th June 2010, 16:58
  5. MVC charts for Qt4
    By wysota in forum Qt-based Software
    Replies: 8
    Last Post: 28th September 2006, 16:06

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.