From b06c01beeb4dc95bd5f0d4bd85bfdf03dd8c8965 Mon Sep 17 00:00:00 2001 From: shenleban tongying Date: Sun, 4 Jun 2023 07:19:34 -0400 Subject: [PATCH] fix: xdxf2html converter failed to parser xml due to   * xml don't have   * in Qt5, this is not a problem because QDomDocument::setContent will somehow accept it. * in Qt6, this will be rejected --- src/dict/xdxf2html.cc | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/dict/xdxf2html.cc b/src/dict/xdxf2html.cc index 8bdf7481..36151e1c 100644 --- a/src/dict/xdxf2html.cc +++ b/src/dict/xdxf2html.cc @@ -97,7 +97,7 @@ string convert( string const & in, DICT_TYPE type, map < string, string > const if ( afterEol ) { if( !isLogicalFormat ) - inConverted.append( " " ); + inConverted.append( " " ); // xml don't have   break; } // Fall-through @@ -126,13 +126,27 @@ string convert( string const & in, DICT_TYPE type, map < string, string > const in_data = "
"; in_data += inConverted + "
"; - if( !dd.setContent( QByteArray( in_data.c_str() ), false, &errorStr, &errorLine, &errorColumn ) ) - { - qWarning( "Xdxf2html error, xml parse failed: %s at %d,%d\n", errorStr.toLocal8Bit().constData(), errorLine, errorColumn ); - gdWarning( "The input was: %s\n", in.c_str() ); - return in; +#if ( QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) ) + if ( !dd.setContent( QByteArray( in_data.c_str() ), false, &errorStr, &errorLine, &errorColumn ) ) { + qWarning( "Xdxf2html error, xml parse failed: %s at %d,%d\n", + errorStr.toLocal8Bit().constData(), + errorLine, + errorColumn ); + gdWarning( "The input was: %s\n", in_data.c_str() ); + return in; } +#else + auto setContentResult = dd.setContent( QByteArray::fromStdString( in_data ) ); + if ( !setContentResult ) { + qWarning( "Xdxf2html error, xml parse failed: %s at %d,%d\n", + setContentResult.errorMessage.toStdString().c_str(), + setContentResult.errorLine, + setContentResult.errorColumn ); + gdWarning( "The input was: %s\n", in_data.c_str() ); + return in; + } +#endif QDomNodeList nodes = dd.elementsByTagName( "ex" ); // Example