Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QString corruption
Forum Updated to NodeBB v4.3 + New Features

QString corruption

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 725 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Recker
    wrote on last edited by
    #1

    Our app relies on ICU library for internationalization. Up till now, we had a static global variable which would call the function with following line

    Locale::setDefault(Locale(lname), error_code);
    

    to create and initialize the ICU library there by initializing our internationalization library.

    However, with the upgrade of compilers, we are running into static initialization fiasco.
    So we removed that variable and we are making our components to explicitly call the initialization function to boot the i18n library.

    After doing that, we are finding that some of our components (which depend and links against QTCore lib) which uses QString are receiving corrupted characters.
    We internally use char16_t for our cross platform wide character type data and the operation that's failing is as below

    QString toQString( const std::u16string& str )
    {
        return QString(reinterpret_cast<const QChar *>(str.data()), (int)str.size());
    }
    

    This is creating a corrupted QString and we are failing understand as to why this might be happening.

    1. Is there any connection here between initializing the ICU locale library in static global variable (done at very early stages of app loading) and QString class being good while in other case its behaving badly ?
    2. Does QT uses ICU which is initialized in similar fashion using global static variable ?
    raven-worxR 1 Reply Last reply
    0
    • R Recker

      Our app relies on ICU library for internationalization. Up till now, we had a static global variable which would call the function with following line

      Locale::setDefault(Locale(lname), error_code);
      

      to create and initialize the ICU library there by initializing our internationalization library.

      However, with the upgrade of compilers, we are running into static initialization fiasco.
      So we removed that variable and we are making our components to explicitly call the initialization function to boot the i18n library.

      After doing that, we are finding that some of our components (which depend and links against QTCore lib) which uses QString are receiving corrupted characters.
      We internally use char16_t for our cross platform wide character type data and the operation that's failing is as below

      QString toQString( const std::u16string& str )
      {
          return QString(reinterpret_cast<const QChar *>(str.data()), (int)str.size());
      }
      

      This is creating a corrupted QString and we are failing understand as to why this might be happening.

      1. Is there any connection here between initializing the ICU locale library in static global variable (done at very early stages of app loading) and QString class being good while in other case its behaving badly ?
      2. Does QT uses ICU which is initialized in similar fashion using global static variable ?
      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Recker

      reinterpret_cast<const QChar *>(str.data())

      this won't/can't ever work
      std::u16string cannot be cast to an "arbitrary" class.

      untested:

      QString::fromUtf16( str.data() );
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      6
      • R Offline
        R Offline
        Recker
        wrote on last edited by Recker
        #3
        This post is deleted!
        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved