Results 1 to 10 of 10

Thread: BSTR to QString Conversion

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: BSTR to QString Conversion

    Quote Originally Posted by _Stefan View Post
    This probably works:
    It is my understanding that this will not work as the first 4 bytes of a BSTR contain the length of the string, so you would have to compensate for this. Maybe QString convertedBSTR((QChar*) &bstr[4], wcslen(bstr)); ?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

  3. #3
    Join Date
    Nov 2011
    Posts
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: BSTR to QString Conversion

    Try:

    std::wstring intermediateString(myBSTR, SysStringLen(myBSTR);
    QString finalString = QString::fromStdWString(intermediateString);

    -K

  4. The following user says thank you to hvkleist for this useful post:

    bmn (16th February 2012)

  5. #4
    Join Date
    May 2007
    Posts
    131
    Thanks
    17
    Thanked 4 Times in 2 Posts

    Default Re: BSTR to QString Conversion

    No need to use std:
    QString qstr((QChar*)bstr, ::SysStringLen(bstr));

Similar Threads

  1. Char* <-> QString implicit conversion
    By kingfinn in forum Qt Programming
    Replies: 3
    Last Post: 15th March 2010, 08:26
  2. char* to QString: conversion
    By abghosh in forum Qt Programming
    Replies: 9
    Last Post: 8th March 2010, 09:32
  3. qreal -> QString conversion
    By MarkoSan in forum Newbie
    Replies: 2
    Last Post: 13th April 2008, 14:37
  4. QString iso 8859-1 conversion
    By mattia in forum Newbie
    Replies: 11
    Last Post: 21st January 2008, 14:17
  5. conversion from QString to const uint8 *
    By vishal.chauhan in forum Qt Programming
    Replies: 3
    Last Post: 19th February 2007, 13:14

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
  •  
Qt is a trademark of The Qt Company.