devNo = this->OpenReader( 0, sPort ); return this->d" /> devNo = this->OpenReader( 0, sPort ); return this->d" /> devNo = this->OpenReader( 0, sPort ); return this->d"/>

qDebug() affects the result of program execution

116 Views Asked by At
int ICOperator::ICStarts( const char *port )
{
    if ( NULL == OpenReader) { qDebug() << ""; }

    this->devNo = this->OpenReader( 0, sPort );

    return this->devNo;
}

As the function show, qDebug() is not actually executed, but program will crash, if comment as below:

int ICOperator::ICStarts( const char *port )
{
  //  if ( NULL == OpenReader) { qDebug() << ""; }

    this->devNo = this->OpenReader( 0, sPort );

    return this->devNo;
}

What happens in qDebug()? May stack error?

1

There are 1 best solutions below

1
ΦXocę 웃 Пepeúpa ツ On

you app is crashing not because you are using the debug but coz your logic is not avoiding to use an invalid pointer.

if OpenReader is NULL then this is invalid OpenReader( 0, sPort )

int ICOperator::ICStarts( const char *port )
{
    if ( NULL == OpenReader)
    { 
         qDebug() << "Invalid OpenReader";
         return -1; 
    }

    this->devNo = this->OpenReader( 0, sPort );
    return this->devNo;
}