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. Load library and calling functions of main app

Load library and calling functions of main app

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 2.2k 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.
  • E Offline
    E Offline
    Eugene
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      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.

      Greetz, Jeroen

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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 ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • E Offline
          E Offline
          Eugene
          wrote on last edited by
          #4

          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!!!");
          }
          @

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

            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.

            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