Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Question about manipulating single facets of QLocale



  • Hi all,
    the following code is working:

    struct comma_separator : std::numpunct<char> {
        virtual char do_decimal_point() const override { return '#'; }
    };
    
    int main(int argc, char *argv[])
    {
        const double number = 1000.25;
    
            std::cout << number;
            std::cout.imbue(std::locale(std::cout.getloc(), new comma_separator));
            std::cout << "\"different\" locale: " << number << '\n';
    }
    

    How can I get this work with QTextStream ?

    Please no answers containing references to the QLocale::toXXX methods.
    I just want to change the behaviour of a QTextStream.

    Thanks and have fun
    Norbert



  • QTextStream uses QLocale internally to determine the decimal separator so I can't see any way you can do what you are asking. sorry



  • @VRonin Can it bee that I have been so unclear ?
    If I ask for a way to get the code (which mainpulates the std::locale object of cout (which is a stream by the way )) working with QTextStream, it should be evident, that I have to maipulate the QLocale Object which is used by QTextStream. So the answer is: because I want to manipulate the Qlocale used by QTextStream.

    Any answer which will help me will be appriciated.


  • Lifetime Qt Champion

    Hi,

    Please watch the tone you use when answering. Being aggressive with people taking time to help you is not a good idea.

    As it is, QLocale doesn't provide the equivalent of std::locale's facets thus @VRonin is right, you can't do what you want without going down modifying Qt's internals.


Log in to reply