Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Big latency when calling standard C++ code from Qt
Qt 6.11 is out! See what's new in the release blog

Big latency when calling standard C++ code from Qt

Scheduled Pinned Locked Moved Mobile and Embedded
10 Posts 3 Posters 4.0k Views 1 Watching
  • 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.
  • H Offline
    H Offline
    hongquan
    wrote on last edited by
    #1

    Hello,

    I'm writing an app for Maemo, using a library in standard C++ and Qt for GUI. I have a problem when calling a std::C++ function from My Qt code: I takes almost 3 second only to enter the function.
    Here is my code when calling the function (with timer):
    https://gitorious.org/mverbiste/mverbiste/blobs/24c4175dd69b2b8e87506247a34d4e765d86bb31/mainwindow.cpp#line181
    !http://i.imgur.com/u2wiS.png(Caller)!

    And inside getConjugation(), with timer:
    !http://i.imgur.com/J0rRl.png(Callee)!

    Here is the result with the time recorded, running on Maemo phone:
    !http://i.imgur.com/Ruo50.png(Time measured)!

    Can you help me point out the cause of problem? Can it be fixed?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      disperso
      wrote on last edited by
      #2

      I am somewhat surprised by this, and I have not many ideas, but first one question: Is that code in some external dynamic library, or is part of your executable? I have zero knowledge about linkers, and that kind of things, but I think that Maemo/MeeGo had some kind of "booster" that started applications from a preloaded executable that links against Qt in order to improve startup time, because dynamic linking is somewhat slow on Linux. Something like KDE's kdeinit. Maybe is something worth investigating.

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hongquan
        wrote on last edited by
        #3

        The code is not in external dynamic library. It is part of my executables.

        1 Reply Last reply
        0
        • H Offline
          H Offline
          hongquan
          wrote on last edited by
          #4

          I wonder if the freVerbDic variable is forced to initialize again when passed to called function (I have little experience in C++)?

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

            I'm no C++ expert at all, but I understand that since you are passing a constant reference, there is no change at all.

            Can you do a test changing the reference with a pointer, and see if changes anything?

            Also, maybe something Maemo specific is happening, but maybe is not and maybe this question is more suited to the C++ forum (that's why I hate forums, all this fragmentation). Can you test the code on a normal computer (if is crossplatform) or in an emulator to see if it makes a difference?

            1 Reply Last reply
            0
            • H Offline
              H Offline
              hongquan
              wrote on last edited by
              #6

              Thanks
              I tried on normal computer (via "Simulator" on QtSDK), it is OK (fast).
              In the code above, the "freVerbDic" variable is defined as:
              @FrenchVerbDictionary *freVerDict@
              So, how to pass as pointer?

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7

                Perhaps its a revenge for using camel case naming convention for non-Qt C++ identifier names, eh eh.

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  disperso
                  wrote on last edited by
                  #8

                  [quote author="hongquan" date="1352480105"]Thanks
                  I tried on normal computer (via "Simulator" on QtSDK), it is OK (fast).
                  In the code above, the "freVerbDic" variable is defined as:
                  @FrenchVerbDictionary *freVerDict@
                  So, how to pass as pointer?[/quote]

                  In getConjugation declaration, you have to say that is a pointer, that is, use something like: "FrenchVerbDictionary* fvd". Then, were the function is invoked, use "&freVerbDic".

                  IF you are new with C/C++, search "pass by pointer" or "pass by reference".

                  1 Reply Last reply
                  0
                  • H Offline
                    H Offline
                    hongquan
                    wrote on last edited by
                    #9

                    [quote author="disperso" date="1352815647"]
                    In getConjugation declaration, you have to say that is a pointer, that is, use something like: "FrenchVerbDictionary* fvd". Then, were the function is invoked, use "&freVerbDic".

                    IF you are new with C/C++, search "pass by pointer" or "pass by reference".[/quote]

                    Wonderful! I solved this.
                    I changed to pass argument like this
                    @getConjugation(*freVerbDic,...@
                    Thanks disperso.
                    My old code made freVerbDic to re-initialize. I confirmed this by checking its properties outside and inside getConjugation() function.

                    @matti I don't know about the naming convention. Could you let me know?
                    I'm a Python & C guy, just begin with C++.

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      disperso
                      wrote on last edited by
                      #10

                      Ah, great. Nice that you fixed it because I wasn't really sure what else could it be!

                      Since you say that know C, just note that normally you can use pointers in C++ the same way you are used to. References are very similar.

                      In some places of Qt (or just in C++, like with the "this" keyword) pointers are used instead of references, so is not a big deal (in my opinion). But learn how to use them, since they are useful, too.

                      About matti: he was probably joking. Normally Qt uses "CamelCase", and I don't see why you should not use it. An interesting article that mentions a little bit about this things: http://doc.qt.digia.com/qq/qq13-apis.html

                      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