how to override qtcharts QBarSeries?
-
@crane_jiang said in how to override qtcharts QBarSeries?:
so I try to rewrite the codes in the source code
In that case you have to build and install this Qt modue.
Did you do that?@jsulm
yes, I rebuild the qt library, we are developing embedded qt applications and use our customed qt libs.
we just want to not select useless modules, but not to changed default libs source.
so we think override in our application is better than modify qt lib source. -
@jsulm
yes, I rebuild the qt library, we are developing embedded qt applications and use our customed qt libs.
we just want to not select useless modules, but not to changed default libs source.
so we think override in our application is better than modify qt lib source.@crane_jiang Not sure I understand you. If you change Qt code you have to rebuild the Qt module where this code is located. How else would this work?
If you rebuild the Qt module and it still does not work then make sure you properly installed your custom built module. -
@crane_jiang Not sure I understand you. If you change Qt code you have to rebuild the Qt module where this code is located. How else would this work?
If you rebuild the Qt module and it still does not work then make sure you properly installed your custom built module.@jsulm
I make changes in qt lib just to see if it can work, setLabelsFormat() can show customed bar labels with set/category more than just value.
but I don't want to use this way seriously.I want to do this by override official QHorizontalStackedBarSeries codes.
I find the related codes are under qt-everywhere-src-5.15.12/qtcharts/src/charts/barchart/horizontal/stacked/.
(1) horizontalstackedbarchartitem_p.h
(2) qhorizontalstackedbarseries.h
(3) qhorizontalstackedbarseries_p.h
(4) horizontalstackedbarchartitem.cpp
(5) qhorizontalstackedbarseries.cpp
I want to replace these files with my own ones, myhorizontalstackedbarchartitem_p.h myqhorizontalstackedbarseries.h myqhorizontalstackedbarseries_p.h myhorizontalstackedbarchartitem.cpp myqhorizontalstackedbarseries.cpp, respectively.
and then use my customed class myQHorizontalStackedBarSeriesto whose generateLabelsText() support display bar labels to replace official QHorizontalStackedBarSeries.
and I do have add "QT += charts-private" in project.pro file.I can't upload my override codes in reply,
so I upload it to my space link my qtcharts override codes
there are several build errors such as
undefined reference to `__imp__ZTVN8QtCharts29myQHorizontalStackedBarSeriesE' undefined reference to `__imp__ZTVN8QtCharts36myQHorizontalStackedBarSeriesPrivateE'
I don't know how to fix these errors.
thank you -
@jsulm
I make changes in qt lib just to see if it can work, setLabelsFormat() can show customed bar labels with set/category more than just value.
but I don't want to use this way seriously.I want to do this by override official QHorizontalStackedBarSeries codes.
I find the related codes are under qt-everywhere-src-5.15.12/qtcharts/src/charts/barchart/horizontal/stacked/.
(1) horizontalstackedbarchartitem_p.h
(2) qhorizontalstackedbarseries.h
(3) qhorizontalstackedbarseries_p.h
(4) horizontalstackedbarchartitem.cpp
(5) qhorizontalstackedbarseries.cpp
I want to replace these files with my own ones, myhorizontalstackedbarchartitem_p.h myqhorizontalstackedbarseries.h myqhorizontalstackedbarseries_p.h myhorizontalstackedbarchartitem.cpp myqhorizontalstackedbarseries.cpp, respectively.
and then use my customed class myQHorizontalStackedBarSeriesto whose generateLabelsText() support display bar labels to replace official QHorizontalStackedBarSeries.
and I do have add "QT += charts-private" in project.pro file.I can't upload my override codes in reply,
so I upload it to my space link my qtcharts override codes
there are several build errors such as
undefined reference to `__imp__ZTVN8QtCharts29myQHorizontalStackedBarSeriesE' undefined reference to `__imp__ZTVN8QtCharts36myQHorizontalStackedBarSeriesPrivateE'
I don't know how to fix these errors.
thank you@crane_jiang said in how to override qtcharts QBarSeries?:
I want to replace these files with my own ones
Where? In your project source tree? How should QtCharts module know anything about your own implementation of that class?
You either subclass QHorizontalStackedBarSeries, or, if it does not help, alter Qt implementation and rebuild the Qt module.
-
@jsulm
yes, I add these 5 myxxx.h/cpp in my project tree, rather than change official source code directly.
does it matters?and I have valid company qt-license,
how can I connect official support engineer for help? -
@jsulm
yes, I add these 5 myxxx.h/cpp in my project tree, rather than change official source code directly.
does it matters?and I have valid company qt-license,
how can I connect official support engineer for help?@crane_jiang Here I guess: https://www.qt.io/qt-support/
-
@crane_jiang said in how to override qtcharts QBarSeries?:
I want to replace these files with my own ones
Where? In your project source tree? How should QtCharts module know anything about your own implementation of that class?
You either subclass QHorizontalStackedBarSeries, or, if it does not help, alter Qt implementation and rebuild the Qt module.
@jsulm said in how to override qtcharts QBarSeries?:
How should QtCharts module know anything about your own implementation of that class?
yes, that's the point. the error message seems it don't know how to new the class, class is in-complete...
I tried to make my class myqhorizontalstackedbarseries as child of qhorizontalstackedbarseries, but the Constructor ~Constructor() become complex, and get lots of errors。 so I make myqhorizontalstackedbarseries as brothers of qhorizontalstackedbarseries, copy all the member definitions and functions, but still get lots of errors. -
Hi,
You are meddling with the private APIs so you need to link to the private Qt libraries knowing all the consequence that are explained in the header of these files.
-
Hi,
You are meddling with the private APIs so you need to link to the private Qt libraries knowing all the consequence that are explained in the header of these files.
@SGaist
yes, the private API is used.
the Qhorizontalstackedbarseries class new() QHorizontalStackedBarSeriesPrivate, and then the private new() the HorizontalStackedBarChartItem which has generateLabelText() to show value labels,
so I have to rewrite all of them. but always get compile errors.
do you have any other simple way suggested to show labels containing set/category index?
thank you. -
@jsulm
I make changes in qt lib just to see if it can work, setLabelsFormat() can show customed bar labels with set/category more than just value.
but I don't want to use this way seriously.I want to do this by override official QHorizontalStackedBarSeries codes.
I find the related codes are under qt-everywhere-src-5.15.12/qtcharts/src/charts/barchart/horizontal/stacked/.
(1) horizontalstackedbarchartitem_p.h
(2) qhorizontalstackedbarseries.h
(3) qhorizontalstackedbarseries_p.h
(4) horizontalstackedbarchartitem.cpp
(5) qhorizontalstackedbarseries.cpp
I want to replace these files with my own ones, myhorizontalstackedbarchartitem_p.h myqhorizontalstackedbarseries.h myqhorizontalstackedbarseries_p.h myhorizontalstackedbarchartitem.cpp myqhorizontalstackedbarseries.cpp, respectively.
and then use my customed class myQHorizontalStackedBarSeriesto whose generateLabelsText() support display bar labels to replace official QHorizontalStackedBarSeries.
and I do have add "QT += charts-private" in project.pro file.I can't upload my override codes in reply,
so I upload it to my space link my qtcharts override codes
there are several build errors such as
undefined reference to `__imp__ZTVN8QtCharts29myQHorizontalStackedBarSeriesE' undefined reference to `__imp__ZTVN8QtCharts36myQHorizontalStackedBarSeriesPrivateE'
I don't know how to fix these errors.
thank you@crane_jiang said in how to override qtcharts QBarSeries?:
undefined reference to
__imp__ZTVN8QtCharts29myQHorizontalStackedBarSeriesE' undefined reference to
__imp__ZTVN8QtCharts36myQHorizontalStackedBarSeriesPrivateE'I am not sure as I don't use Qt5, don't have Qt source and don't use Windows or MSVC. But these errors are from MSVC and look like it is failing to find symbols from
__declspec(dllimport)
/__declspec(dllexport)
. These come from theQ_CHARTS_PRIVATE_EXPORT
/Q_CHARTS_EXPORT
in the source files you have copied from Qt. I think e.g.class Q_CHARTS_EXPORT myQHorizontalStackedBarSeries
resolves toclass __declspec(dllimport) myQHorizontalStackedBarSeries
, which is why the symbols start with__imp__
. But that is for importing symbols from a DLL, which is what it is in Qt code, but in your code the class you have added does not reside in a DLL.Try removing/commenting out the
Q_CHARTS_PRIVATE_EXPORT
/Q_CHARTS_EXPORT
at least in yourmyhorizontalstackedbarchartitem_p.h
&myqhorizontalstackedbarseries.h
to make them regular, non-DLL classes? Does that make it compile, or at least change the "undefined references"? I don't know whether the whole thing will work or whether you will encounter other problems but this may be the resolution for this linker issue. -
@jsulm
yes, I add these 5 myxxx.h/cpp in my project tree, rather than change official source code directly.
does it matters?and I have valid company qt-license,
how can I connect official support engineer for help?@crane_jiang said in how to override qtcharts QBarSeries?:
yes, I add these 5 myxxx.h/cpp in my project tree, rather than change official source code directly.
does it mattersAgain: when you modify the Qt source you have to recompile it. What's so hard to understand here?
-
@crane_jiang said in how to override qtcharts QBarSeries?:
yes, I add these 5 myxxx.h/cpp in my project tree, rather than change official source code directly.
does it mattersAgain: when you modify the Qt source you have to recompile it. What's so hard to understand here?
@Christian-Ehrlicher
As I understand it and the user's attached files, for right or for wrong they are trying to introduce a subclass ofQHorizontalStackedBarSeries
, and they are doing this in their own program, not in Qt library code. They have simply copied a few files from Qt sources to allow them to make appropriate new code.I may be mistaken --- please feel free to correct me --- but I do not see why that should require alteration or recompilation of existing Qt code. Hence my reply above suggesting that at present they have a problem with compiling the code they copied from when it is to be compiled within a project rather than as a standalone library/DLL, which is how the code they have copied from is written in Qt.
I do not disagree that the simplest might be to simply make their changes or additions in the Qt QtCharts source code and recompile. Especially since neither QtCharts nor Qt 5.15 is going to undergo changes. But if they want to try putting the new code in their own project rather than into Qt source with recompile I am currently thinking that is possible, with the modification I suggested earlier. If that does not work then they may have to take the Qt source route.
-
@Christian-Ehrlicher
As I understand it and the user's attached files, for right or for wrong they are trying to introduce a subclass ofQHorizontalStackedBarSeries
, and they are doing this in their own program, not in Qt library code. They have simply copied a few files from Qt sources to allow them to make appropriate new code.I may be mistaken --- please feel free to correct me --- but I do not see why that should require alteration or recompilation of existing Qt code. Hence my reply above suggesting that at present they have a problem with compiling the code they copied from when it is to be compiled within a project rather than as a standalone library/DLL, which is how the code they have copied from is written in Qt.
I do not disagree that the simplest might be to simply make their changes or additions in the Qt QtCharts source code and recompile. Especially since neither QtCharts nor Qt 5.15 is going to undergo changes. But if they want to try putting the new code in their own project rather than into Qt source with recompile I am currently thinking that is possible, with the modification I suggested earlier. If that does not work then they may have to take the Qt source route.
@JonB said in how to override qtcharts QBarSeries?:
. They have simply copied a few files from Qt sources to allow them to make appropriate new code.
And how should this work? Apart from the name clash the export macros are wrong.
-
@JonB said in how to override qtcharts QBarSeries?:
. They have simply copied a few files from Qt sources to allow them to make appropriate new code.
And how should this work? Apart from the name clash the export macros are wrong.
@Christian-Ehrlicher said in how to override qtcharts QBarSeries?:
the export macros are wrong.
Which is exactly what I wrote above in https://forum.qt.io/post/829183. I don't know about "name clash".
Anyway if you are sure this cannot be done by adding a new subclass in own code then I am sure you will be right and the OP would be best just changing the existing Qt source.