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

I am searching plugins skeleton



  • I want write code editor based on QPlainTextEdit and highlighters from https://github.com/KDE/syntax-highlighting.
    I prefer modular form with plugins. Plugin must be loaded/unloaded dynamically. In editor wil multitab with editor factory. Plugins for syntax highlight, theme, type correctness, encryption for encrypted documents...
    How can I write framework and plugins?


  • Qt Champions 2018

    @AndrzejB ,
    I have never tried it, but I think that QPluginLoader Class can be used.
    so please refer sample document as below.


  • Lifetime Qt Champion

    @AndrzejB you can also have a look at QtCreators sorce code, as it does much of what you want.

    Please note that plugins should not be unloaded, and I think it is rarely useful.



  • I have created dynamically loaded plugins for my application by following the Plug & Paint example. This example uses QPluginLoader for loading the plugins at run-time. One thing that turned out to be a bit more tricky than I anticipated based on the example is to identify the correct plugin path on the various platforms. So, here is a bit of my code that covers the Loading part:

        QDir PluginLocation = QDir(qApp->applicationDirPath());
    
        #if defined(Q_OS_WIN)
            if (PluginLocation.dirName().toLower() == "debug" || PluginLocation.dirName().toLower() == "release")
                PluginLocation.cdUp();
        #elif defined(Q_OS_MAC)
            QDir PackageLocation = QDir(qApp->applicationDirPath());
            PackageLocation.cdUp();
            PackageLocation.cdUp();
            PackageLocation.cdUp();
            PackageLocation.cdUp();
            if (PackageLocation.dirName().toLower() == "debug" || PackageLocation.dirName().toLower() == "release") {
                PluginLocation.cdUp();
                PluginLocation.cdUp();
                PluginLocation.cdUp();
                PluginLocation.cd("plugins");
            } else {
                PluginLocation.cdUp();
                PluginLocation.cd("PlugIns");
            }
        #endif
    
        #if not defined (Q_OS_MAC)
            PluginLocation.cd("plugins");
        #endif
    
        foreach (QString FileName, PluginLocation.entryList(QDir::Files)) {
            if (QLibrary::isLibrary(FileName)) {
                QPluginLoader Loader(PluginLocation.absoluteFilePath(FileName));
                QObject *Plugin = Loader.instance();
                if (Plugin) {
                    // Do something useful with the plugin as in Plug & Paint example
                }
            }
        }
    


  • Mac binary directory is so deep ? - (n times PackageLocation.cdUp())


  • Lifetime Qt Champion

    Hi,

    No it's not, the binary is by default in MyApp.app/Content/MacOS while the plugins are in MyApp.app/Content/PlugIn. You may modify some of that however following the recommended layout (as Qt does for you) is way simpler.



  • @SGaist That is indeed correct when deploying the app but not when running from QtCreator. Hence, this not so nice construction... If anybody has a nicer solution, I am all ears :)


  • Lifetime Qt Champion

    To be sure we're on the same idea, you would like to have them at the correct place when you build your application ?


Log in to reply