none
TCHAR zu std::wstring zuweisung funktioniert in Vs2010exp aber nicht in Qt mit vs compiler RRS feed

  • Frage

  • Hallo! Ich habe folgenden code:

    for(int n=0; n<nLines+1;n++)                                                 //Read all lines in the textbox 
           {
               TCHAR FetchedString[200]={0};            
               lResult = SendMessageW(hChatText, EM_GETLINE, nLines - n, (LPARAM)FetchedString);	      //read the n'thed line        
               *reinterpret_cast<WORD *>(FetchedString) = _countof(FetchedString);                        //Initialize the buffer with size of ....see msdn        
               nLength = SendMessageW(hChatText,EM_GETLINE,(WPARAM)nLines - n,(LPARAM)FetchedString);     //Find out how many characters are collected from the line fetched
               FetchedString[nLength] = '\0';                                                             //Adding the string terminating NULL at the end    
               std::wstring data;                                                                         //Define wstring object
               data=FetchedString;                                                                        //Type cast TCHAR[] string to wstring
               vFetchedLines.push_back(data);                                                             //Appends new line at end of the list
           }

    Wenn ich dieses in VS2010exp compiliere ist alles ok.

    Nun verwende ich den selben code in einem Qt widget based Projekt. Dort bekomme ich den Fehler:

    error: C2679: binary '=' : no operator found which takes a right-hand operand of type 'TCHAR [200]' (or there is no acceptable conversion)
    c:\Program\Microsoft Visual Studio 10.0\VC\INCLUDE\xstring(707): could be 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(std::basic_string<_Elem,_Traits,_Ax> &&)'
    with
    [
        _Elem=wchar_t,
        _Traits=std::char_traits<wchar_t>,
        _Ax=std::allocator<wchar_t>
    ]
    c:\Program\Microsoft Visual Studio 10.0\VC\INCLUDE\xstring(761): or       'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(const std::basic_string<_Elem,_Traits,_Ax> &)'
    with
    [
        _Elem=wchar_t,
        _Traits=std::char_traits<wchar_t>,
        _Ax=std::allocator<wchar_t>
    ]
    c:\Program\Microsoft Visual Studio 10.0\VC\INCLUDE\xstring(766): or       'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(const _Elem *)'
    with
    [
        _Elem=wchar_t,
        _Traits=std::char_traits<wchar_t>,
        _Ax=std::allocator<wchar_t>
    ]
    c:\Program\Microsoft Visual Studio 10.0\VC\INCLUDE\xstring(771): or       'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(_Elem)'
    with
    [
        _Elem=wchar_t,
        _Traits=std::char_traits<wchar_t>,
        _Ax=std::allocator<wchar_t>
    ]
    while trying to match the argument list '(std::wstring, TCHAR [200])'

    Ist an dem code etwas grundlegendes falsch was nur durch "Zufall" in VS funktioniert oder liegt die Ursache eher bei Qt?

    Grüße

    Samstag, 23. Juni 2012 19:59

Antworten

  • Du hast vermutlich kein Unicode Projekt!

    D.h. ein FetchedString ist dann eben ein char! Wenn Du schon nur an Unicode Daten interessiert bist verwende gleich wchar_t statt TCHAR.
    TCHAR brauchst Du nur, wenn Du Dein Programm als Ansi-Code oder Unicode kompilieren willst.


    Martin Richter -- MVP for VC++ [Germany] -- http://blog.m-ri.de

    Sonntag, 24. Juni 2012 07:49
    Moderator

Alle Antworten

  • Du hast vermutlich kein Unicode Projekt!

    D.h. ein FetchedString ist dann eben ein char! Wenn Du schon nur an Unicode Daten interessiert bist verwende gleich wchar_t statt TCHAR.
    TCHAR brauchst Du nur, wenn Du Dein Programm als Ansi-Code oder Unicode kompilieren willst.


    Martin Richter -- MVP for VC++ [Germany] -- http://blog.m-ri.de

    Sonntag, 24. Juni 2012 07:49
    Moderator
  • Danke, in VS weiß ich wo ich in den Settings auf Unicode umstelle, in Qt habe ich es noch nicht gefunden. Aber mit wchar_t funktioniert es.
    Sonntag, 24. Juni 2012 10:57