Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QLibrary: isLoaded() not matching!



  • 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


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



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



  • @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.


Log in to reply