Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Create a plugins
Qt 6.12 LTS is out! See what's new in the release blog

Create a plugins

Scheduled Pinned Locked Moved General and Desktop
35 Posts 4 Posters 29.9k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #10

    1st project:

    operanditem.h

    @ #if defined(MY_NGWIDGETS_LIBRARY)

    define MYSHARED_EXPORT Q_DECL_EXPORT

    #else

    define MYSHARED_EXPORT Q_DECL_IMPORT

    #endif

    class MYSHARED_EXPORT OperandItem : public QObject
    {.....}@

    main.c

    @qmlRegisterType<OperandItem> (“Operands”, 1, 0, “MYOperand”);@

    pro file

    @QT += core gui
    QT += declarative
    QT += network
    QT += xml

    TARGET = NGWidgets
    TEMPLATE = lib
    DEFINES += MY_NGWIDGETS_LIBRARY
    CONFIG += qt plugin
    DESTDIR = lib
    OBJECTS_DIR = tmp
    MOC_DIR = tmp

    SOURCES +=
    main.cpp \
    Operands/operanditem.cpp
    HEADERS +=
    Operands/operanditem.h

    @

    2nd project:

    in some qml file i write:

    @ import QtQuick 1.0
    import Operands 1.0

    Rectangle{
    MYOperand{}
    }@

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #11

      You better append your second .pro file too.

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #12

        Please have another read through this "article":http://developer.qt.nokia.com/doc/qt-4.7/declarative-tutorials-extending-chapter6-plugins.html#id-8c522ec4-43c2-4344-a4a4-148efcc18b7d and you'll see that you also need to write a plugin class derived from QDeclarativeExtensionPlugin that your 2nd project's QML engine will call the registerTypes() function of in order to register them with your 2nd project.

        This plugin class seems to be completely missing from you 1st project.

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #13

          i have this class inherit from QDeclarativeExtensionPlugin and create the plugin.
          i don't know what i need to add to the 2nd project (in the pro file) to make it work with the new module...

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #14

            You need to edit the qmldir file in your 2nd project so that it points at the path where the plugin library from your 1st project is located.

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #15

              the dll file was created in the build-desktop directory(in the debug) and not in the QtCreator\lib\ directory... even when i copy the dll to this place it does not work

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #16

                in the pro file i write:

                @QTPLUGIN += NGWidgets
                LIBS += -L"C:/Qt/Projects/NGWidgets-build-desktop/debug"
                LIBS += -lNGWidgets@

                in the folder "C:/Qt/Projects/NGWidgets-build-desktop/debug"
                i have the dll (NGWidgets.dll)

                but i got the error:
                :-1: error: cannot find -lngwidgetsd
                collect2: ld returned 1 exit status

                1 Reply Last reply
                0
                • ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #17

                  I don't think that your 2nd project's .pro file needs to mention the NGWidgets plugin lib at all. The qmldir file tells the QDeclarativeEngine where it can dllopen your plugin library from.

                  Also the error message you posted does not match the .pro file you have posted the error message is referring to ngwidgetsd.dll whereas the .pro file mentions NGWidgets.dll (not the trailing d).

                  In your 1st project (the plugin one) make sure you are using the Q_EXPORT_PLUGIN2 macro as is mentioned in the docs:

                  @
                  Q_EXPORT_PLUGIN2( NGWidgets, NGWidgetsPlugin )
                  @

                  where I have assumed that your plugin class (the one derived from QDeclarativeExtensionPlugin) is called NGWidgetsPlugin (since you have not shown it to us).

                  Try using a qmldir file for your 2d project that looks like this:

                  @
                  plugin NGWidgets C:/Qt/Projects/NGWidgets-build-desktop/debug
                  @

                  and in your .qml file using

                  @
                  import NGWidgets 1.0
                  @

                  1 Reply Last reply
                  0
                  • ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #18

                    that exaclly what i did - and i create alse qmldir file in the first project (as shown in the example)....

                    in this link : http://doc.qt.nokia.com/latest/plugins-howto.html
                    they say that the pro file of the 2nd project should be changed...

                    1 Reply Last reply
                    0
                    • ? Offline
                      ? Offline
                      A Former User
                      wrote on last edited by
                      #19

                      I do not see anything in that document relating to qml plugins. Rather than this constant back and forth can you provide a zip file of your two projects that we can try to fix up for you please?

                      1 Reply Last reply
                      0
                      • ? Offline
                        ? Offline
                        A Former User
                        wrote on last edited by
                        #20

                        i can't post all my code. but this is the main classes:

                        1st project :

                        ngwidgetsplugin.h

                        @#include <QDeclarativeExtensionPlugin>

                        class NGWidgetsPlugin: public QDeclarativeExtensionPlugin
                        {
                        Q_OBJECT
                        public:
                        void registerTypes(const char *uri);
                        };@

                        ngwidgetsplugin.cpp

                        @#include <QtDeclarative>
                        #include <QtPlugin>
                        //.....more includes for files

                        void NGWidgetsPlugin::registerTypes(const char *uri)
                        {
                        qmlRegisterType<OperandItem> (uri, 1, 0, "MYOperand");

                           //................. 
                        

                        }

                        Q_EXPORT_PLUGIN2(NGWidgets, NGWidgetsPlugin)@

                        .pro

                        @QT += core gui
                        QT += declarative
                        QT += network

                        #TARGET = NGWidgets
                        TEMPLATE = lib
                        CONFIG += qt plugin
                        DESTDIR = lib
                        OBJECTS_DIR = tmp
                        MOC_DIR = tmp

                        SOURCES += ...
                        HEADERS += ...
                        OTHER_FILES += ...
                        @

                        qmldir

                        @plugin NGWidgets lib@

                        2nd project - use the plugin

                        .pro

                        @QT += core gui
                        QT += declarative
                        QT += network

                        SOURCES += ...
                        HEADERS += ...
                        OTHER_FILES += ...@

                        qmldir

                        @plugin NGWidgets C:/Qt/Projects/NGWidgets-build-desktop/debug @

                        app.qml

                        @import QtQuick 1.0
                        import NGWidgets 1.0

                        Rectangle
                        {
                        MYOperand{...}
                        }

                        @

                        i got the error : module "NGWidgets" is not installed
                        for line 2

                        1 Reply Last reply
                        0
                        • ? Offline
                          ? Offline
                          A Former User
                          wrote on last edited by
                          #21

                          Be also aware that you usually cannot mix release and debug code.

                          1 Reply Last reply
                          0
                          • ? Offline
                            ? Offline
                            A Former User
                            wrote on last edited by
                            #22

                            so how can i connect to the plugin, that locate in the debug dir?

                            1 Reply Last reply
                            0
                            • ? Offline
                              ? Offline
                              A Former User
                              wrote on last edited by
                              #23

                              I just wanted to point out that if you compile your application in debug mode you should compile your plugins in debug mode too (same goes for release builds).

                              However - have you tried to "trace the module import":http://developer.qt.nokia.com/doc/qt-4.7/qdeclarativedebugging.html?

                              EDIT: Are you sure that path in your qmldir file is correct? You instruct qmake to place your library in a "lib" directory but your path points to the "debug" directory. -As far as I have understood the documentation you do not need both - the qmldir and the import statement. You can omit one.-

                              1 Reply Last reply
                              0
                              • ? Offline
                                ? Offline
                                A Former User
                                wrote on last edited by
                                #24

                                yes, i give the path to the location of NGWidgets.dll , and this dll is locate in the debug dir of the plugin project and also in the lib directory (in 2 cases it's not recognize the "module")...

                                1 Reply Last reply
                                0
                                • ? Offline
                                  ? Offline
                                  A Former User
                                  wrote on last edited by
                                  #25

                                  The .dll in your debug directory is most likely an outdated version, as all new versions are moved to the lib directory (as specified as DESTDIR in the .pro file). You are pointing to the wrong directory in your qmldir file.

                                  Have you already tried tracing the module import?

                                  1 Reply Last reply
                                  0
                                  • ? Offline
                                    ? Offline
                                    A Former User
                                    wrote on last edited by
                                    #26

                                    ok - you right , i changed it to :
                                    @plugin NGWidgets C:/Qt/Projects/NGWidgets-build-desktop/lib@
                                    but still have the same problem

                                    1 Reply Last reply
                                    0
                                    • ? Offline
                                      ? Offline
                                      A Former User
                                      wrote on last edited by
                                      #27

                                      Have you already tried tracing the module import?

                                      1 Reply Last reply
                                      0
                                      • ? Offline
                                        ? Offline
                                        A Former User
                                        wrote on last edited by
                                        #28

                                        this is the output:
                                        QDeclarativeImportDatabase::addImportPath: "C:\QtSDK\Desktop\Qt\4.7.3\mingw\imports"
                                        QDeclarativeImportDatabase::addImportPath: "C:/Qt/Projects/App-build-desktop/debug"
                                        QDeclarativeImports(C:/Qt/Projects/App/app.qml)::addImport: "." -1.-1 File as ""
                                        QDeclarativeImports(C:/Qt/Projects/App/app.qml)::addImport: "QtQuick" 1.0 Library as ""
                                        QDeclarativeImports(C:/Qt/Projects/App/app.qml)::addImport: "NGWidgets" 1.0 Library as ""
                                        C:/Qt/Projects/App/app.qml:3:1: module "NGWidgets" is not installed

                                        1 Reply Last reply
                                        0
                                        • ? Offline
                                          ? Offline
                                          A Former User
                                          wrote on last edited by
                                          #29

                                          is this a good output?

                                          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
                                          • Unsolved