Hello. I have a plugins folder next to the executable, in which the plugins are located, each in a separate folder, and the folder name matches the plug-in name. So, I need to get a list of all these plugins. I myself do this:

QDir pluginsDir = QDir::current(); pluginsDir.cd("plugins"); for(const QString& dir : pluginsDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) { //Это так получаю имя файла QString pluginName = pluginsDir.absolutePath() + "/" + dir +"/" + dir + ".dll"; /* ... */ } 

Here pluginsDir.entryList (...) will return a list of all folders. The question arose: is there any other way to get a list of all plugins?

    2 answers 2

    and what this method is not suitable? It can be improved a little by using std :: transform (or the like). Here is a sample code .

    Update

    What do you need speed? the beauty of the code? something else?

    if the speed - in any case, rest against the file system. But while the plug-ins will be a dozen or two, everything will be quite fast. For the future, you can make a list caching. And it will be a strong acceleration.

    The beauty of the code is another. It may even be necessary to create a special class, which by the name of the plug-in returned its name (caching inside if necessary).

    • It does not seem effective to me. And thanks for the link, I read - rabbitinspace
    • @KoVadim, I'm not sure that caching the list of plugins can significantly speed up processing as a whole, because when accessing a plugin (dlopen ()), the kernel itself will still read the same directory file. - avp
    • Thank you, then leave it as it is :) - rabbitinspace

    At one time, I received a solid gain in speed when I refused entryList and switched to QDirIterator .
    True, it was on a directory with 1000+ files.