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. [Solved]across platform
QtWS25 Last Chance

[Solved]across platform

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 2.9k Views
  • 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.
  • P Offline
    P Offline
    pmjz
    wrote on last edited by
    #1

    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));@
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #2

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

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pmjz
        wrote on last edited by
        #3

        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;
        }@

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dbzhang800
          wrote on last edited by
          #4

          Why use wchar_t width of which is dependent on platform?

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dbzhang800
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • P Offline
              P Offline
              pmjz
              wrote on last edited by
              #6

              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

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

                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?

                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
                • P Offline
                  P Offline
                  pmjz
                  wrote on last edited by
                  #8

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

                  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