[Solved]across platform



  • Hi guys, please me out
    If I wanna make the following expression run on window and ubuntu, what is the better way to do, or the below is good enough:
    @for(int i=sym.count(); i > 0; i -=4)
    {
    num = (((num << 5) + num) + (num >> 27));
    if( i <= 2)
    {
    break;
    }
    num2 = (((num2 << 5) + num2) + (num2 >> 27));
    }
    }

    qint32 key = (num + (num2 * 1566083941));@

  • Moderators

    How does this have anything to do with portability between Windows and Ubuntu? It's pretty straightforward C++ code. The only remotely Qt-related code is the quint32.

    I'm not really sure what aspect of the you're questioning.

    (It doesn't even seem to be a complete snippet of code. Mismatched braces.)



  • yes, you are right, my problem is :running my app is good on win7,getHashCode()is ok, but when I run the same app on ubuntu, getHashCode() generate a wrong value.I suspect that the error is from the integal type. the following is the relating code

    @qint32 neoseis::getMyStringHashCode(const QString& sym)
    {
    qint32 num = 352654597;
    wchar_t *warray = new wchar_t[c+1];
    sym.toWCharArray(warray);
    delete []warray;
    return key;
    }@



  • Why use wchar_t width of which is dependent on platform?



  • BTW: Are you sure that "running my app is good on win7"

    @
    wchar_t warray = new wchar_t[c+1];
    //...
    int
    numPtr = (int*) warray;
    @

    IMO, such codes perhaps work under some linux system, but will not work correctly under Windows.



  • yes, We develop our app on Win7, and now we wanna run it on ubuntu. buinding the app is ok and when I run app, tell me a pointer = 0. and then I trace app and suspect some type cause the problem . generally, app is ok on win7



  • Keep in mind that:

    The width of wchar_t is compiler-specific and can be as small as 8 bits. Consequently, programs that need to be portable across any C or C++ compiler should not use wchar_t for storing Unicode text. The wchar_t type is intended for storing compiler-defined wide characters, which may be Unicode characters in some compilers.

    If you use Qt, why not go with QString all the way and avoid portability issues?



  • thank you guys, the problem is fixed. the trick is:
    @
    QString sym;
    const ushort array = sym.utf16();
    int
    intValue = (int*)array;
    @


Log in to reply
 

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