[QGIS-Developer] C++ debugging policy/strategy

Sandro Santilli strk at kbt.io
Fri Sep 23 09:51:36 PDT 2022


I often find myself in need to place console printouts to better
understand the flow of data in qgis while analizing bugs, but I never
know how to implement such printouts.

The attempts I usually make are:

  (1)

    qDebug() << "XXX: whatever is " << whatever;

  (2)

    std::cerr << "XXX: whatever is " << whatever << std::endl;

  (3)

    QgsDebugMsg( QString( "XXX: whatever is %1".arg( whatever) );


And I do see each of them used in the sourcetree, but I'm not clear
which of them needs which operator, and I feel like defining 3
operators to support all possible calling conventions is overkill.

An example of such redundancy is in src/core/geometry/qgsrectangle.h
which has:

  CORE_EXPORT QDataStream &operator<<( QDataStream &out, const QgsRectangle &rectangle );

  inline std::ostream &operator << ( std::ostream &os, const QgsRectangle &r) {...}

Is there a development guide to recommend one approach over the other ?
I could not find a specific chapter on this here:

  https://docs.qgis.org/3.22/en/docs/developers_guide/codingstandards.html

--strk;

  Libre GIS consultant/developer
  https://strk.kbt.io/services.html


More information about the QGIS-Developer mailing list