Hi,
The following is my test codes.

Qt Code:
  1. char label[MAX_LABEL_LENGTH];
  2. QList<double> lMajorTicks, lMinorTicks;
  3. _pEngine -> buildTicks( _oAttribute._fStart, _oAttribute._fEnd, _nMaxMajorTickNumber, lMajorTicks, lMinorTicks );
  4.  
  5. int nCount = lMajorTicks.count();
  6. for( int i = 0; i < nCount; i ++ )
  7. {
  8. int nPos = (lMajorTicks[i]-_oAttribute._fStart)*_fScale;
  9. painter -> drawLine( nPos, _oAttribute._nMargin, nPos, _oAttribute._nMargin+_oAttribute._nMajorTickLen );
  10.  
  11. memset( label, '\0', MAX_LABEL_LENGTH );
  12. sprintf( label, _oAttribute._sMajorLabelFormat, lMajorTicks[i] );
  13. QString text = QString::fromStdString( label );
  14. QRect rc = painter -> boundingRect( QRect(0,0,0,0), Qt::AlignCenter, text );
  15. QRect qrc = QRect( nPos, _oAttribute._nMargin+_oAttribute._nMajorTickLen+15, rc.width()+10, rc.height()+10 );
  16. if( i > 0 && i < nCount-1);
  17. painter -> drawText( qrc, Qt::AlignCenter, text );
  18.  
  19. }
To copy to clipboard, switch view to plain text mode 
If the drawText() is commented off, the program is ok, or it crashes.
I tried many many times but I failed.
I don't know why and how to solve it.
Maybe my way to use QPainter is not right?


Thanks

Nicho