dangling unicode string?



  • 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.



  • 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 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.