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. Crash on App Exit with Plugins
Qt 6.11 is out! See what's new in the release blog

Crash on App Exit with Plugins

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 2.3k Views 2 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.
  • ModelTechM Offline
    ModelTechM Offline
    ModelTech
    wrote on last edited by ModelTech
    #1

    Following the Plug & Paint example, I have created a working application that exploits plugins. However, when I exit my application, I get the message that the program has unexpectedly finished. I have identified the error to be caused by using the QObject returned by QPluginLoader::instance() as second argument in the constructor for QAction as also used in the MainWindow::addToMenu() function of the Plug & Paint example. I have however condensed my code a bit compared to this example:

    foreach (QString File, PluginLocation.entryList(QDir::Files)) {
        if (QLibrary::isLibrary(File)) {
            QPluginLoader Loader(PluginLocation.absoluteFilePath(File));
            QObject *Plugin = Loader.instance();
            if (Plugin) {
                Importer *ImportPlugin = qobject_cast<Importer *>(Plugin);
                if (ImportPlugin) {
                    QAction *ImportAction = new QAction(ImportPlugin->menu() + "...", Plugin); // The second argument causes the crash on exit
                    connect(ImportAction, SIGNAL(triggered()), this, SLOT(onImport()));
                    ImportMenu->addAction(ImportAction);
                }
            }
        }
    }
    

    Any ideas where I should be looking to solve the crashing behavior?

    1 Reply Last reply
    0
    • ModelTechM Offline
      ModelTechM Offline
      ModelTech
      wrote on last edited by ModelTech
      #2

      I found a solution (although I am not sure whether this is the way to go): When loading the plugins as above, I am now storing the corresponding actions in a list. Upon closing the application, I first delete all actions in this list. This approach resolves the crashing behavior, but if anybody has a more appropriate solution, please let me know :)

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

        Hi,

        Out of curiosity, why are you setting the plugin as parent of your QAction ?

        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
        • ModelTechM Offline
          ModelTechM Offline
          ModelTech
          wrote on last edited by ModelTech
          #4

          That's how it is done in the Plug & Paint example and the reason is that one has access to the involved plugin for further processing when the action is performed. And just like the Plug & Paint example, I need this access ;)

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

            What version of Qt are you using ?

            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
            • ModelTechM Offline
              ModelTechM Offline
              ModelTech
              wrote on last edited by ModelTech
              #6

              This is with Qt 5.7.1

              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