Results 1 to 6 of 6

Thread: QTextCodec::setCodecForCStrings() in libraries

  1. #1
    Join Date
    Mar 2006
    Posts
    17
    Thanks
    4

    Question QTextCodec::setCodecForCStrings() in libraries

    Hi!
    Is it good to use QTextCodec::setCodecForCStrings() in external libraries? Will it affect the main application? How can I inform library about used encoding in source? Will using this function in main application affect external libraries? It is difficult to understand, because it's static function.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextCodec::setCodecForCStrings() in libraries

    It will affect all (const char*) to QString and the other way around conversions from the moment it is called.

    Pretty clear.

    Regards

  3. The following user says thank you to marcel for this useful post:

    conexion2000 (10th August 2007)

  4. #3
    Join Date
    Mar 2006
    Posts
    17
    Thanks
    4

    Default Re: QTextCodec::setCodecForCStrings() in libraries

    Even those that are located in dll's? And Qt libs itself?

    How can I inform library itself about used encoding?

  5. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextCodec::setCodecForCStrings() in libraries

    Yes, everything.
    If you set a code for C strings and call a function located in a dll, like this(assuming the function takes a QString parameter):
    Qt Code:
    1. dllFunction("String with weird encoding");
    To copy to clipboard, switch view to plain text mode 
    Then the QString built from the const char* will be affected by the codec.

    If you don't want this behavior then you could define sections in your applications in which you set the code to NULL, do some stuff, and set it back to utf8.

    EDIT: you can make a global variable and/or function in your lib that you use as some sort of initializer.
    For example:
    Qt Code:
    1. setLibraryCodec(currentCodec);
    To copy to clipboard, switch view to plain text mode 

    Regards

  6. #5
    Join Date
    Mar 2006
    Posts
    17
    Thanks
    4

    Default Re: QTextCodec::setCodecForCStrings() in libraries

    I rather meant internal functions in a library. Assuming returnString() belongs to SomeLib which is compiled as DLL:
    QString SomeLib::returnString()
    {
    //do some stuff
    QString someString("here it goes..");
    //do here something
    }
    Will be some string encoded in a codec set in main app?

  7. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextCodec::setCodecForCStrings() in libraries

    Yes, if you call this function in the context of the application, then I believe it will.
    It is better to test it, since I could be wrong .

    However, it does not make any sense not to apply the codec since QString has a static QTextCode member which is set by setCodecForCStrings.
    Therefore every QString built after this member is set will be affected.

    Regards

  8. The following user says thank you to marcel for this useful post:

    conexion2000 (10th August 2007)

Similar Threads

  1. Replies: 2
    Last Post: 8th March 2007, 22:22
  2. how to add new libraries to QT
    By whoops.slo in forum Newbie
    Replies: 3
    Last Post: 12th January 2007, 11:15
  3. Qt 3.3 libraries
    By ToddAtWSU in forum Qt Programming
    Replies: 1
    Last Post: 21st December 2006, 17:25
  4. Standardization on libraries
    By brcain in forum General Discussion
    Replies: 13
    Last Post: 16th August 2006, 22:56
  5. Replies: 4
    Last Post: 7th March 2006, 08:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.