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: isLoaded() not matching!
Qt 6.11 is out! See what's new in the release blog

QLibrary: isLoaded() not matching!

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 452 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.
  • F Offline
    F Offline
    fem_dev
    wrote on last edited by
    #1

    Here is a simple example of my main C++ application that loads my custom shared library called "mylib.so.1.0.0" that is placed in the same folder of the main application.
    The wired thing is that: In the console output it said that the mylib was not loaded, but it can call and execute the run() function that is inside the shared library.

        QLibrary mylib("./mylib");
    
        std::cout << "Is Loaded: " << mylib.isLoaded() << std::endl;
        std::cout << mylib.errorString().toStdString() << std::endl;
    
        typedef void (*func_run)(void);
    
        func_run run = (func_run) mylib.resolve("run");
    
        if (run == NULL) {
            std::cerr << "[API ERROR]: Unable to load the run() function!" << std::endl;
            exit(1);
        }
    
        run(); // WORKS GOOD!
    

    Console Output:

    Is Loaded: 0   // <-- WHY?
    Unknown error
    Shared Library: Inside the RUN() function 
    

    My System:

    • Ubuntu 20.04 x64
    • CMake 3.16.3
    • g++ 9.3
    • Qt 5.15.1
    F 1 Reply Last reply
    0
    • F fem_dev

      Here is a simple example of my main C++ application that loads my custom shared library called "mylib.so.1.0.0" that is placed in the same folder of the main application.
      The wired thing is that: In the console output it said that the mylib was not loaded, but it can call and execute the run() function that is inside the shared library.

          QLibrary mylib("./mylib");
      
          std::cout << "Is Loaded: " << mylib.isLoaded() << std::endl;
          std::cout << mylib.errorString().toStdString() << std::endl;
      
          typedef void (*func_run)(void);
      
          func_run run = (func_run) mylib.resolve("run");
      
          if (run == NULL) {
              std::cerr << "[API ERROR]: Unable to load the run() function!" << std::endl;
              exit(1);
          }
      
          run(); // WORKS GOOD!
      

      Console Output:

      Is Loaded: 0   // <-- WHY?
      Unknown error
      Shared Library: Inside the RUN() function 
      

      My System:

      • Ubuntu 20.04 x64
      • CMake 3.16.3
      • g++ 9.3
      • Qt 5.15.1
      F Offline
      F Offline
      fem_dev
      wrote on last edited by
      #2

      @fem_dev I solve...To get a right result of isLoaded() you must call load() before it!

      B 1 Reply Last reply
      0
      • F fem_dev

        @fem_dev I solve...To get a right result of isLoaded() you must call load() before it!

        B Offline
        B Offline
        Bonnie
        wrote on last edited by Bonnie
        #3

        @fem_dev

        To get a right result of isLoaded() you must call load() before it!

        I think that's not true, the result of isLoaded() is right during the whole time.
        When you haven't called load(), it is not loaded, so isLoaded() should return false.

        1 Reply Last reply
        3

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved