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. QLibrary - Not Working in Release
Forum Updated to NodeBB v4.3 + New Features

QLibrary - Not Working in Release

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.6k 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.
  • webzoidW Offline
    webzoidW Offline
    webzoid
    wrote on last edited by webzoid
    #1

    I'm using a QLibrary instance to resolve symbols in a 3rd party library.

    When debugging, I can happily resolve symbols and execute the resolved functions without fail. However, when in release mode, I'm no longer able to call these resolved functions without an exception occurring and the application terminates immediately.

    One of the functions which is causing the crash has the following signature:

    typedef int (* fnStRg)(LPCSTR, LPCSTR, LPCSTR);
    

    And I resolve this as follows:

    QLibrary lib;
    lib.setFileName("cad.dll");
    lib.load();
    // All OK so far in both release and debug
    
    fnStRg myFunc = (fnStRg)lib.resolve("StRg");
    // All still OK in both release and debug
    
    myFunc("PARAM1", "PARAM2", "PARAM3");
    // All is OK in debug but in release mode, the above function call generates an exception
    // Commenting out the above line no longer caused an exception
    

    For reference, LPCSTR is defined as:

    typedef _Null_terminated_ CONST CHAR *LPCSTR, *PCSTR;
    

    And I have tried passing the arguments as QString("PARAM1").toStdString().c_str() with no success.

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

      @webzoid said in QLibrary - Not Working in Release:

      fnStRg myFunc = (fnStRg)lib.resolve("StRg");
      // All still OK in both release and debug

      Hi! First of all, you need to check if the function could actually be resolved, if not, myFunc will be 0.

      fnStRg("PARAM1", "PARAM2", "PARAM3");

      Eh, no. A call to the resolved function would be: myFunc("PARAM1", "PARAM2", "PARAM3");.

      webzoidW 1 Reply Last reply
      1
      • ? A Former User

        @webzoid said in QLibrary - Not Working in Release:

        fnStRg myFunc = (fnStRg)lib.resolve("StRg");
        // All still OK in both release and debug

        Hi! First of all, you need to check if the function could actually be resolved, if not, myFunc will be 0.

        fnStRg("PARAM1", "PARAM2", "PARAM3");

        Eh, no. A call to the resolved function would be: myFunc("PARAM1", "PARAM2", "PARAM3");.

        webzoidW Offline
        webzoidW Offline
        webzoid
        wrote on last edited by
        #3

        @Wieland Sorry, I've updated my question to correct the 'myFunc' call - I am actually calling it this way, not how I originally had it.

        The function is correctly resolved, I can verify that the resolved address is valid in both debug and release mode

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

          Hi! Did you get this to work in the meantime? Otherwise please try to create a minimal working example (or better: not working example) so we can try to reproduce this.

          1 Reply Last reply
          0
          • webzoidW Offline
            webzoidW Offline
            webzoid
            wrote on last edited by
            #5

            @Wieland I have just managed to get this working. I started a new QWidgets application and brought across the code to load the 3rd party library. When I build for release with this new application, everything works fine - I must be doing something silly in my other application.

            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