Results 1 to 7 of 7

Thread: QPolarChart

  1. #1
    Join Date
    Jan 2020
    Posts
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default QPolarChart

    I am attempting to use QPolarChart, so I use:
    Qt Code:
    1. #include <QtCharts/QPolarChart>
    To copy to clipboard, switch view to plain text mode 
    However, I get an error: QtCharts/QPolarChart: no such file or directorty
    I tried to install the library, thus:
    sudo apt-get install -y libqt5charts5
    but I still get the same error. I am using Kubuntu 18.04, Kdevelop 5.2.1 and Cmake. I am not using qmake, so its version number (4.8.7) is probably not relevant? Anything else I need to install?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,240
    Thanks
    239
    Thanked 672 Times in 662 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: QPolarChart

    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.

  3. #3
    Join Date
    Jan 2020
    Posts
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: QPolarChart

    Installing libqt5charts5-dev helped, in the sense that I can now decleare
    Qt Code:
    1. QPolarChart *chart;
    To copy to clipboard, switch view to plain text mode 
    But
    Qt Code:
    1. QPolarChart *chart = new QPolarChart();
    To copy to clipboard, switch view to plain text mode 
    results in what is probably a linking error:
    '... undefined reference to `QtCharts::QPolarChart::QPolarChart(QGraphicsItem* , QFlags<Qt::WindowType>)'
    Do I need to modify my CMakeLists.txt file?

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,240
    Thanks
    239
    Thanked 672 Times in 662 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: QPolarChart

    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?
    <=== 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.

  5. #5
    Join Date
    Jan 2020
    Posts
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: QPolarChart

    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?

  6. #6
    Join Date
    Jan 2020
    Posts
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: QPolarChart

    I might have celebrated a bit prematurely, as the following code (adapted from the example in the QPolarChart Class doc.);
    Qt Code:
    1. m_angularAxis = new QValueAxis();
    2. m_angularAxis->setTickCount(9);
    3. m_angularAxis->setLabelFormat("%.1f");
    4. m_angularAxis->setShadesVisible(true);
    5. m_angularAxis->setShadesBrush(QBrush(QColor(249, 249, 255)));
    6. m_chart->addAxis(m_angularAxis, QPolarChart::PolarOrientationAngular);
    To copy to clipboard, switch view to plain text mode 
    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 to
    Qt Code:
    1. m_chart->addAxis(m_radialAxis, QPolarChart::PolarOrientationRadial);
    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:
    1. find_package(Qt5Charts)
    2. target_link_libraries(myApp Qt5::Widgets Qt5::Charts)
    To copy to clipboard, switch view to plain text mode 
    but I cannot see what it might me. Am I missing something?

  7. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,240
    Thanks
    239
    Thanked 672 Times in 662 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: QPolarChart

    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.

    using namespace QtCharts
    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.
    <=== 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.

Similar Threads

  1. Radial Axis in QPolarChart
    By bobbyael in forum Qt Programming
    Replies: 1
    Last Post: 31st August 2015, 12:15

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.