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. dangling unicode string?
Qt 6.11 is out! See what's new in the release blog

dangling unicode string?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 1 Posters 1.8k 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.
  • ? This user is from outside of this forum
    ? This user is from outside of this forum
    Guest
    wrote on last edited by
    #1

    Hi, I'm trying to display a unicode string on a QMessageBox from the QTableWidget horizontalHeaderItem,
    using the code below:
    @ wchar_t c[300];
    QString s;
    s = qtw->horizontalHeaderItem(0)->text();
    s.toWCharArray(c);
    QMessageBox::information(0,0,QString::fromWCharArray(c));
    @
    the horizontalHeaderItem's text is correctly drawn, however I get on the MessageBox a dangling unicode string containing the horizontalHeaderItem's text plus other dangling characters that are not part from the horizontalHeaderItem's text.
    so what's wrong here? and how to solve that problem? thanks.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MuldeR
      wrote on last edited by
      #2

      I can't see anything wrong with that code excerpt.

      However, it could be simplified to:
      @QString s = qtw->horizontalHeaderItem(0)->text();

      //pointer remains valid, until ``s´´ is modified/deleted!
      const wchar_t c = (const wchar_t) s.utf16();

      QMessageBox::information(0,0,QString::fromUtf16((const ushort*)c));@

      My OpenSource software at: http://muldersoft.com/

      Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

      Go visit the coop: http://youtu.be/Jay...

      1 Reply Last reply
      0
      • ? This user is from outside of this forum
        ? This user is from outside of this forum
        Guest
        wrote on last edited by
        #3

        [quote author="MuldeR" date="1400331764"]I can't see anything wrong with that code excerpt.

        However, it could be simplified to:
        @QString s = qtw->horizontalHeaderItem(0)->text();

        //pointer remains valid, until ``s´´ is modified/deleted!
        const wchar_t c = (const wchar_t) s.utf16();

        QMessageBox::information(0,0,QString::fromUtf16((const ushort*)c));@[/quote]

        many thanks! that really solved my problem, the string now is shown 100% correctly! thanks again.

        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