Request received from the POSTGRES base the values ​​of the DateTime. In the database, the DateTimeEND NULL value, respectively, must be NULL in a variable, but when checking either validity or NULL ( if( !m_dtDateTimeBGN.isNULL() ) ) application drops SIGSEGV. Tried to initialize with an empty constructor m_dtDateTimeEND = QDateTime(); but the result is the same.

  ... QDateTime m_dtDateTimeBGN; QDateTime m_dtDateTimeEND; ... if( !oSqlRecord.value( "BGN_DATE" ).isNull() ) { m_dtDateTimeBGN = oSqlRecord.value( "BGN_DATE" ).toDateTime() ; } else { m_dtDateTimeBGN = QDateTime(); } if( !oSqlRecord.value( "END_DATE" ).isNull() ) { m_dtDateTimeEND = oSqlRecord.value( "END_DATE" ).toDateTime(); } else { m_dtDateTimeEND = QDateTime(); } QString CLiqMeterCommissioning::getPeriodLiqMeter() const { QString sPeriod; if( !m_dtDateTimeBGN.isValid() ) { if( !m_dtDateTimeEND.isValid() )// Здесь падает { sPeriod = MainWindow::AMR_TR( "Был в эксплуатации с %1 до %2" ) .arg( m_dtDateTimeBGN.toString( "dd MMMM yyyy hh:mm" ) ) .arg( m_dtDateTimeEND.toString( "dd MMMM yyyy hh:mm" ) ); } else { sPeriod = MainWindow::AMR_TR( "В эксплуатации с %1" ) .arg( m_dtDateTimeBGN.toString( "dd MMMM yyyy hh:mm" ) ); } } else { if( !m_dtDateTimeEND.isValid() ) { sPeriod = MainWindow::AMR_TR( "Был в эксплуатации до %1" ) .arg( m_dtDateTimeEND.toString( "dd MMMM yyyy hh:mm" ) ); } else { } } return sPeriod; } 
  • A minimally reproducible example would be, but it’s not clear what m_dtDateTimeBGN is - Vladimir Martyanov
  • @ Vladimir Martianov This is a class field. The question has changed. - Evgeny Druzhinin
  • 2
    And how do we know that getPeriodLiqMeter is called earlier than initialization code? : D - gil9red
  • @ gil9red you are right! The function that initializes the parameters did not return a value, while the compiler for some reason did not swear. - Evgeny Druzhinin

1 answer 1

The problem was that the function that loads the parameters from the database and then initializes the members of the object did not return values, while the main logic did not break and the problem was clearly not reproducible. With all this, the compiler for some reason did not swear at the absence of the return operator

 DatabaseStruct::CLiqMeterCommissioning CDatabaseDriverPSQL::load_liq_commissioning( const QUuid &oCommissioningUuid ) { AMR::DatabaseStruct::CLiqMeterCommissioning oLiqMetCommissioning; if( !oCommissioningUuid.isNull() ) { oLiqMetCommissioning.m_oLiqCommissioningUUid = oCommissioningUuid; AMR::Database::CQueryResult oQueryResult = select_liq_commissioning( oCommissioningUuid ); if( !oQueryResult.isError() ) { if( oQueryResult.oSqlQuery.first() ) { QSqlRecord oSqlRecord = oQueryResult.oSqlQuery.record(); oLiqMetCommissioning.setCommissioningParams( oSqlRecord ); return oLiqMetCommissioning; // строка отсутствовала } } else AMR_ASSERT_FALSE(); } else AMR_ASSERT_FALSE(); return DatabaseStruct::CLiqMeterCommissioning(); // строка отсутствовала } 
  • one
    Because an explicit return is optional. But usually in such cases, there is at least a warning . - αλεχολυτ