Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Too frequent postEvent caused no responding



  • Re: sendPostedEvents() or processEvents() causes SIGSEGV

    Hello sir, i have one similar problem.
    In my project, there is one GUI and a thread to receive data. Data will be posted to GUI about 10 times per second, and my GUI will draw a grid with new data and history data in one pixmap and show it. By my test, one pixmap will take about 40ms, so it will take about 400ms to draw pixmap per second. So I think there should not hava any problem.
    But in test, the GUI can't response to some mouse operations like resize and click. When I reduce the post frequency to 5/s, the GUI looked well. In addition, I also set the customevent priority less than Qt::LowEventPriority, no effect.


  • Qt Champions 2019

    @lingyu-0 Can you show your code where you're drawing?



  • sure!

    for (i = 0; i < nPageRow; i++)
        {
            QColor color = cellForeground(row, 0);
            if (isCellFlash(row, 0))
            {
                if (nColorMode == E_Color_Dark)
                {
                    color = color.dark();
                }
                else if (nColorMode == E_Color_Light)
                {
                    color = color.light();
                }
            }
    
            if (getColorMode())
            {
                m_pPainter->fillRect(0, (i + 1)*m_nRowHeight, m_nClientWidth, m_nRowHeight, QBrush(color));
                color = Qt::black;
            }
    
            if (isSelectRow(row))
            {
                m_pPainter->fillRect(0, (i + 1)*m_nRowHeight, m_nClientWidth, m_nRowHeight, QBrush(m_SelectColor));
            }
            m_pPainter->setPen(color);
    
            if (m_bShowRowNo)
                nColWidthSum = m_nNoRowWidth;
            else
                nColWidthSum = 0;
            bool isFirst = true;
            col = m_nFirstPageCol;
            for (j = 0; j < m_nPageCols; j++)
            {
                if (m_pColShow[col] == 0)
                {
                    col++;
                    continue;
                }
                qstr = text(row, col);
                nShowNum = 0;
                if (!qstr.isNull() && !qstr.isEmpty())
                {
                    nCharWidth = m_pPainterFM->width(qstr);
                    if (nCharWidth > 0)
                    {
                        nShowNum = (m_pColWidth[col] - 2 * g_nMarginWidth)*(qstr.length()) / nCharWidth;
                        nShowNum = nShowNum > (int)qstr.length() ? (int)qstr.length() : nShowNum;
                    }
                    qstr = qstr.left(nShowNum);
                    if (false)
                    {
                        m_pPainter->drawText(nColWidthSum + g_nMarginWidth + 10, (i + 1)*m_nRowHeight, m_pColWidth[col] - g_nMarginWidth, m_nRowHeight, Qt::AlignVCenter | Qt::AlignLeft, qstr);
                        QPixmap pixmap = QPixmap::fromImage(getRowIcon(row));
                        m_pPainter->drawPixmap(nColWidthSum, (i + 1)*m_nRowHeight + m_nRowHeight / 3, pixmap);
                        isFirst = false;
                    }
                    else
                    {
                        m_pPainter->drawText(nColWidthSum + g_nMarginWidth, (i + 1)*m_nRowHeight, m_pColWidth[col] - g_nMarginWidth, m_nRowHeight, Qt::AlignVCenter | Qt::AlignLeft, qstr);
                    }
                }
                nColWidthSum += m_pColWidth[col];
                col++;
            }
            row++;
        }
    

    Text information is drawn here, and tables are drawn in other parts. I think drawText() takes the most time.


  • Qt Champions 2019

    @lingyu-0 Maybe you should take a look at https://doc.qt.io/qt-5/qtcharts-index.html instead of doing it manually?



  • @jsulm
    I didn't get the proper class in qtcharts. I need to show my data in a table like QTableWidget but it's more slowly.


  • Lifetime Qt Champion

    Hi,

    If it's table data... why not make a model with it and use a QTableView ?


Log in to reply