skip to Main Content

I have Qt compiled static, but when I run my application I get this error:

qrc:/files/particles/particles.qml:2:1: module "QtQuick.Particles" plugin "particlesplugin" not found 
     import QtQuick.Particles 2.0 
     ^

My imports related to QML are these:

import QtQuick 2.5
import QtQuick.Particles 2.0

I tried to follow the documentation:

#include <QtPlugin>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);     
    Q_IMPORT_PLUGIN(QtQuick2Plugin)
    Q_IMPORT_PLUGIN(QtQuick2ParticlesPlugin) // <--- cause error
    Q_IMPORT_PLUGIN(QtQmlMetaPlugin)
    Q_IMPORT_PLUGIN(QtQmlPlugin)
    Q_IMPORT_PLUGIN(QtQmlModelsPlugin)
    Q_IMPORT_PLUGIN(QtQmlWorkerScriptPlugin)

But I’m getting this compilation error:

1>main.obj : error LNK2019: unresolved external symbol "struct QStaticPlugin const __cdecl qt_static_plugin_QtQuick2ParticlesPlugin(void)" (?qt_static_plugin_QtQuick2ParticlesPlugin@@YA?BUQStaticPlugin@@XZ) referenced in function main

I searched the source for proper way to import this plugin and I have found it at C:Qt6.6.0_staticqtdeclarativesrcparticles

in the file particlesplugin_init.cpp:

#include <QtPlugin>
Q_IMPORT_PLUGIN(QtQuick2ParticlesPlugin)

Why is the compilation throwing that error?

I’m compiling using Visual Studio 2022.

I tested adding #pragma comment(lib, "particlesplugin.lib") into the int main... code above

and the compiler complained about not finding the lib.

I have them added to my project properties:

C/C++ -> General -> Additional Include Directories -> C:Qt6.6.0_staticqmlQtQuickParticles

Linker -> Input -> particlesplugin.lib

When recompiled, now I’m getting a different error:

1>particlesplugin.lib(particlesplugin_QtQuick2ParticlesPlugin.cpp.obj) : error LNK2019: unresolved external symbol "void __cdecl qml_register_types_QtQuick_Particles(void)" (?qml_register_types_QtQuick_Particles@@YAXXZ) referenced in function "public: static __cdecl `public: static void (__cdecl*__cdecl QtPrivate::QMetaTypeForType<class QtQuick2ParticlesPlugin>::getDefaultCtr(void))(class QtPrivate::QMetaTypeInterface const *,void *)'::`5'::<lambda_1>::<lambda_invoker_cdecl>(class QtPrivate::QMetaTypeInterface const *,void *)" (?<lambda_invoker_cdecl>@<lambda_1>@?4??getDefaultCtr@?$QMetaTypeForType@VQtQuick2ParticlesPlugin@@@QtPrivate@@SAP6AXPEBVQMetaTypeInterface@4@PEAX@ZXZ@SA@01@Z)

I also get this external symbol error for every other QtQuick plugin that I try to import using Q_IMPORT_PLUGIN and not only the particlesplugin.

I can’t find anything about this in the documentation, what’s going on?

2

Answers


  1. Chosen as BEST ANSWER

    This issue is a bug, follow the bugreport: https://bugreports.qt.io/browse/QTVSADDINBUG-1173

    Qt/MSBuild is not providing all the necessary link dependencies.


  2. I have also suffered from this issue but i found the right way to do it.
    First you need to find the correct name of your plugin in the source code:
    for example: quickparticlesystem is the file class name. You can use this website to find it : https://codebrowser.dev/qt6/qtdeclarative/src/particles/qquickparticlesystem.cpp.html

    After this you should apply the camelCase:
    quickParticleSystem
    And the add Q at the first place and Plugin at the end:
    QQuickParticleSystemPlugin

    So if you do Q_IMPORT_PLUGIN(QQuickParticleSystemPlugin) it should work.

    If you use CMake don’t forget to use qt_import_plugins to import this plugin.

    When i said i had the same issue is because i wanted to import linuxfb and others as a plugin. I have resolved this issue by adding :
    Q_IMPORT_PLUGIN(QLinuxFbIntegrationPlugin)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search