From d51e3c95a93b840a0784404af8e4e9086a386b9c Mon Sep 17 00:00:00 2001 From: vsr Date: Thu, 11 Aug 2016 09:43:21 +0300 Subject: [PATCH] Allow setting / getting QByteArray preference item in Python modules. - Additional change to previous commit - revert a way QByteArray value is stored in the string. --- src/Qtx/QtxResourceMgr.cxx | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Qtx/QtxResourceMgr.cxx b/src/Qtx/QtxResourceMgr.cxx index d0d2d356d..022fb88a8 100644 --- a/src/Qtx/QtxResourceMgr.cxx +++ b/src/Qtx/QtxResourceMgr.cxx @@ -1573,11 +1573,13 @@ bool QtxResourceMgr::value( const QString& sect, const QString& name, QByteArray if ( !value( sect, name, val, true ) ) return false; - if ( val.startsWith( QLatin1String("@ByteArray(") ) && - val.endsWith( QLatin1Char(')' ) ) ) { + if ( val.startsWith( "@ByteArray(" ) && val.endsWith( ')' ) ) { baVal = QByteArray( val.midRef( 11, val.size() - 12 ).toLatin1() ); } else { + if ( val.startsWith( "@ByteArray[" ) && val.endsWith( ']' ) ) { + val = val.mid( 11, val.size() - 12 ); + } baVal.clear(); QStringList lst = val.split( QRegExp( "[\\s|,]" ), QString::SkipEmptyParts ); for ( QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it ) @@ -2058,11 +2060,15 @@ void QtxResourceMgr::setValue( const QString& sect, const QString& name, const Q if ( checkExisting() && value( sect, name, res ) && res == val ) return; - QString result; - result = QLatin1String("@ByteArray("); - result += QString::fromLatin1(val.constData(), val.size()); - result += QLatin1Char(')'); + char buf[8]; + QStringList lst; + for ( int i = 0; i < val.size(); i++ ) + { + ::sprintf( buf, "#%02X", (unsigned char)val.at( i ) ); + lst.append( QString( buf ) ); + } + QString result = QString( "@ByteArray[%1]" ).arg( lst.join( " " ) ); setResource( sect, name, result ); } -- 2.39.2