--- a/Globals/__init__.py Fri Aug 25 16:14:48 2017 +0200 +++ b/Globals/__init__.py Sat Aug 26 16:49:16 2017 +0200 @@ -263,7 +263,7 @@ @param args tuple of arguments from QCoreApplication.translate (tuple) @return translated string (string) """ - if QT_VERSION_STR.startswith('4'): + if QT_VERSION_STR.startswith('4.'): args = list(args) args.insert(3, QCoreApplication.CodecForTr) return QCoreApplication.translate(*args) @@ -314,7 +314,7 @@ ############################################################################### -## functions for extended string handling +## functions for version handling ############################################################################### @@ -384,6 +384,23 @@ return sep.join(groups) +def strToQByteArray(txt): + """ + Module function to convert a Python string into a QByteArray. + + @param txt Python string to be converted + @type str, bytes, bytearray, unicode + """ + if sys.version_info[0] == 2: + if isinstance(txt, unicode): # __IGNORE_WARNING__ + txt = txt.encode("utf-8") + else: + if isinstance(txt, str): + txt = txt.encode("utf-8") + + return QByteArray(txt) + + ############################################################################### ## functions for converting QSetting return types to valid types ###############################################################################