PDA

View Full Version : How to set a QString to a previously defined codec name



Testostheron
10th November 2015, 16:02
Hello to all !

The following scenario is given:

I have a QTextEdit object added to my existing window ui file.

The user can make write operations to that QTextEdit object.

If this is finished, the user can press a button, to tell the pogram,
that the text input is complete is ready to be processed further.

The program enters the slot, whch is defined to process the button - click.

In this slot I fill a QString variable (called txt) with the textEdits toPlainText() methode.

This functions correctly.

Now I have an QString variable (called codecName) , which describes
the textcodec name, to which the QString variable has to be transformed to.

For example, this QString codecName is initialized to "UTF-8".

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
But: It can be any other value, that describes the codec name
which can be found onto the customer system, depending on the
user settings.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

I tried to get information on how to transform the QString txt, which holds
the textEdits toPlainText() value and to transform it using the codec name
assigend to codecName.

Can anyone help me how to perform this operation ?

anda_skoa
10th November 2015, 16:27
QTextCodec::codecForName(), then using QTextCodec::fromUnicode() on the returned object.

Cheers,
_

Testostheron
7th December 2015, 10:03
Thank you for your answer !

It helped a lot !