I am guessing that when you install libqt5charts5 you are getting only the runtime libraries.
You probably also need to install the development files: libqt5charts5-dev
I am guessing that when you install libqt5charts5 you are getting only the runtime libraries.
You probably also need to install the development files: libqt5charts5-dev
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
Installing libqt5charts5-dev helped, in the sense that I can now decleare
But
results in what is probably a linking error:Qt Code:
QPolarChart *chart = new QPolarChart();To copy to clipboard, switch view to plain text mode
'... undefined reference to `QtCharts::QPolarChart::QPolarChart(QGraphicsItem* , QFlags<Qt::WindowType>)'
Do I need to modify my CMakeLists.txt file?
Yes. You probably need to add the name of the charts library to the target_link_libraries() directive. I don't know what that name is on linux - libqt5charts5 maybe?Do I need to modify my CMakeLists.txt file?
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
Modifying the line
target_link_libraries(lydkontroll Qt5::Widgets)
to
find_package(Qt5Charts)
target_link_libraries(lydkontroll Qt5::Widgets Qt5::Charts)
got rid of the linking error message. I also had to inlude
using namespace QtCharts;
in the .h file. Then it compiles, links and runs OK. Although it works, I am not sure how "using namespace QtCharts" is related to QtCharts. Is it needed because QtCharts is a separate module?
I might have celebrated a bit prematurely, as the following code (adapted from the example in the QPolarChart Class doc.);
craches the application. Looks like a segmentation error, although the error message just states that the application has crashed. The strange thing is that if I change the last line toQt Code:
m_angularAxis = new QValueAxis(); m_angularAxis->setTickCount(9); m_angularAxis->setLabelFormat("%.1f"); m_angularAxis->setShadesVisible(true); m_chart->addAxis(m_angularAxis, QPolarChart::PolarOrientationAngular);To copy to clipboard, switch view to plain text mode
there is no crash. So it seems to be related to PolarOrientationAngular. Running it in the debugger causes the debugger to crash, so I must be doing something really daft. I suspect it could be related to my CMakeListe.txt file,Qt Code:
m_chart->addAxis(m_radialAxis, QPolarChart::PolarOrientationRadial);To copy to clipboard, switch view to plain text mode
but I cannot see what it might me. Am I missing something?Qt Code:
find_package(Qt5Charts) target_link_libraries(myApp Qt5::Widgets Qt5::Charts)To copy to clipboard, switch view to plain text mode
If it runs in the debugger, then use the debugger to find where the crash occurs by looking at the call stack at the point of the crash. We aren't sitting there looking over your shoulder, so how are we to know what else you are doing that could cause a problem?
If your CMake script builds an executable, then the problem is not in the CMake script. It's in your code (or your run time environment). Be sure that the Qt installation that find_package() is finding (and building against) is the same one that your run time is calling on to load shared libraries. Use the "ldd" command to find which libraries have been linked to and compare those with your path.
All of the classes in the QtCharts library are in the QtCharts namespace. If you don't want to have to qualify every class with the namespace, you add the "using" directive. Otherwise, every time you declare a QPolarChart instance, you have to declare it as QtCharts::QPolarChart and so forth.using namespace QtCharts
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
The problem is solved. I had just committed a stupid mistake. Thanks for the help.
Wow, I've never done that.I had just committed a stupid mistake.![]()
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
Bookmarks