Qtcharts with visual C++

  • Hi everybody!

    I am working on a project on visual c++ and I try to add a form class with a QChartView inside. In this project :

    • After adding the QtCharts directoy folder and linking qt5Charts.lib with my project,

    • I draw a form with QtDesigner

    • I add a Widget that I promote as a QChartView.

    When I try to compile my project, I have some errors. The origin of these errors seems that in the generated ui_XXX.h of my form, the namespace qtCharts is not used. If I add it manually, the project will compile and seems to work well. The problem is that the line I add is deleted each time the ui_XXX.h is generated.

    Can you, please, tell me, what point which will fixe this probleme that I forgot?

    Here is some part of the code :

    • Here is the class that I create :
    #ifndef TEST_H
    #define TEST_H
    #include "ui_test.h"
    class test : public QMainWindow
    	test(QWidget *parent = 0);
    	Ui::testClass ui;	
    #endif // TEST_H

    This class contains a Ui::testClass element which is generated by the QtDesigner. Here is the code :

    #ifndef UI_TEST_H
    #define UI_TEST_H
    #include <QtCore/QVariant>
    #include <QtWidgets/QAction>
    #include <QtWidgets/QApplication>
    #include <QtWidgets/QButtonGroup>
    #include <QtWidgets/QHeaderView>
    #include <QtWidgets/QMainWindow>
    #include <QtWidgets/QMenuBar>
    #include <QtWidgets/QStatusBar>
    #include <QtWidgets/QToolBar>
    #include <QtWidgets/QWidget>
    #include "QtCharts\qchartview.h"
    //using namespace QtCharts; I have to add this line if I want the compilation works
    class Ui_testClass
        QWidget *centralWidget;
        QChartView *widget; // without namespace this must be QtCharts::QChartView
        QMenuBar *menuBar;
        QToolBar *mainToolBar;
        QStatusBar *statusBar;
    //BLA BLA BLA...

  • @awawawa


    Try in your test.h as follows:

    #ifndef TEST_H
    #define TEST_H
    #include <QtCharts>
    #include <QMainWindow>
    #include "ui_test.h"
    class test : public QMainWindow

    Do not modify your ui_test.h.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.