Load library and calling functions of main app



  • Hello! Sorry for poor language.

    I load library, give him pointer to main app and after that call main app public functions from library . But I get error message.
    "symbol lookup error: /home/jeka/QtPro/MyPlugin/plug/libMy_plug.so: undefined symbol: _ZN10MainWindow8set_textEv"
    What I should to do to call main app publick functions from my plugin?
    If it's hard what I should to learn?



  • Well, without code, no way of telling what you are doing now, or what is the real solution. But loading a QLibrary also needs to "resolve" function pointers to the functions in the library. The symbol lookup error gives an indication that QLibrary couldn't find the requested function. When using a C-API library it should always work. If you use a C++ library you need to use the same compiler for the library and your Qt project, this to do with name mangling.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Since you are using Qt I assume that you have a QApplication, then you don't need to pass the pointer to your QApplication instance around. Just use the qApp macro in your code.

    Your error seems related to a MainWindow class, are you sure that this class is known to your plugin ?



  • Thanks for answers. My code is ugly))
    I write some functions prototype, if it isn't enough. Please tell me how to share my project?
    @
    // mainwindow.cpp
    #include "iface.h" // interface class
    void MainWindow::load_plugins()
    {
    //... other code.
    QPluginLoader loader(dir.absoluteFilePath(strFileName));
    // iface plugin; private member
    plugin = qobject_cast<iface
    >(loader.instance());
    plugin->set_main_app_pointer(this) ;
    //...
    }
    void MainWindow::on_pushButton_clicked()
    {
    plugin->call_mainwindow_function();
    }
    void MyPlugin::call_mainwindow_function()
    {
    //MainWindow *window - my plugin's private member
    qDebug() << window->metaObject()->className(); // give "MainWindow" string
    window->set_label_text(); //Error
    }

    void MainWindow::set_label_text() // main app public function
    {
    ui->label->setText("Hello!!!");
    }
    @



  • Hi,
    It's really not a good idea to let your plugin depend on your application.

    You need to define a Interface class, then use it in both your application and your shared library.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.