Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-124158

Interaction of QValueAxis 'setRange' and 'setTickInterval' causes a problem when using TicksDynamic

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 6.6.1
    • Charts
    • None
    • Qt C++ 6.6.1, Qt Creator 12.0.2, MinGW 64-bit, on Windows 11 for creating a desktop application
    • Windows

    Description

      I'm using Qt C++ 6.6.1, Qt Creator 12.0.2, MinGW 64-bit, on Windows 11 for creating a desktop application.

      I encountered a problem related to the interaction of the Qt library functions 'QValueAxis::setRange' and 'QValueAxis::setTickInterval' when 'TickType' is 'TicksDynamic'.

      I have reduced the problem to a small simple example.  The example has a QGrapicsView that has been promoted (by Qt Creator) to QChartView (see "mainwindow.ui").  The mainwindow has two QPushButton, <Graph 1> and <Graph 2>.  When running the example, first press the button <Graph 1>, then press the button <Graph 2>, which will cause the program to 'hang/crash' while executing the following line of code in 'on_pushButton_2_clicked':
      ```
      m_axisY->setRange(0, 1.0e4); /* the program will CRASH while executing this instruction */
      ```
      I ran the program in the Debugger, but I was unable to obtain a stack trace when it "hung/crashed".  I wasn't even able to kill the application with the Windows Task Manager.

      A zip file of the project is attached.

      After much debugging I identified the problem to be the following:
      When the code for <Graph 1> 'on_pushButton_1_clicked' is executing, it sets the tick interval (via setTickInterval) to 1.0e-10.  Then when the code for <Graph 2> 'on_pushButton_2_clicked' is executing it tries to set the range (via setRange) to 1.0e+4, which crashes the program because the Qt library function 'ChartValueAxisX::calculateLayout' is called from within setRange.

      After clicking <Graph 2> the problem is that the Qt library calls the function 'ChartValueAxisX::calculateLayout' too soon, before the application code has an opportunity to set all of the properties associated with tickType of 'TicksDynamic' for graph 2. 

      In my example, after clicking <Graph 2> the Qt library function 'ChartValueAxisX::calculateLayout' tries to create (on the STACK) a QList containing (1.0e+4/1.0e-10=1.0e+14) 'points' which is too many for the STACK to handle, and is not what my application code is trying to achieve.  The application is trying to create an axis that has 10 major ticks, but the Qt library undesirably is trying to create an axis with trillions of major ticks.

      The Qt library needs a function that can set the 'range', 'tickInterval', and 'tickAnchor' in one AUTONOMOUS operation/function to eliminate the problem; i.e. Qt library needs a function like the following:
      ```
      void QValueAxis::setTicksDynamicInfo (qreal min, qreal max, qreal tickInterval, qreal tickAnchor);
      ```
      That would prevent the Qt library from calling 'ChartValueAxisX::calculateLayout' too soon before all of the necessary properties have been set by the application.

      Note:  My example is an actual set of data from my larger application.  I have multiple data sets that can be graphed by the user selecting the desired dataset from a QListWidget.  I am able to work around this problem by temporarily changing the tickType by calling 'setTickType(QValueAxis::TicksFixed)', then setting all the properties, then changing the tickType back to 'setTickType(QValueAxis::TicksDynamic)' as follows:
      ```
      m_axisY->setTickType(QValueAxis::TicksFixed);
      m_axisY->setRange(0, 1.0e4);
      m_axisY->setTickInterval(1.0e3);
      m_axisY->setTickCount(10); /* this is needed when 'TicksFixed' */
      m_axisY->setTickAnchor(0);
      m_axisY->setTickType(QValueAxis::TicksDynamic); /* will properly use range, interval, and anchor */
      ```
      In summary, the problem occurs when <Graph 2> button is clicked which calls 'm_axisY->setRange(0, 1.0e4)' when the tickInterval was previously set to 1.0e-10 (when <Graph 1> button was clicked), which causes the Qt library to try to add 1.0e14 QList 'points' on the stack.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            e0348803 Miikka Heikkinen
            ericr Eric Ribble
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes