Create a plugins
-
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 -
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
@ -
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... -
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 filesvoid 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 = tmpSOURCES += ...
HEADERS += ...
OTHER_FILES += ...
@qmldir
@plugin NGWidgets lib@
2nd project - use the plugin
.pro
@QT += core gui
QT += declarative
QT += networkSOURCES += ...
HEADERS += ...
OTHER_FILES += ...@qmldir
@plugin NGWidgets C:/Qt/Projects/NGWidgets-build-desktop/debug @
app.qml
@import QtQuick 1.0
import NGWidgets 1.0Rectangle
{
MYOperand{...}
}@
i got the error : module "NGWidgets" is not installed
for line 2 -
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.-
-
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?
-
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 -
Did you place your qmldir file "correctly":http://doc.trolltech.com/4.8-snapshot/qdeclarativemodules.html#installed-modules?
-
Yup only takes 10 minutes! You can find the projects at:
"Project 1 (the QML plugin)":http://www.theharmers.co.uk/busyindicator.tar.gz
"Project 2 (the app using the plugin)":http://www.theharmers.co.uk/simpleqmlapp.tar.gzYou will need to alter the following things to make it work on your system:
In busyindicator.pro edit the line
@
target.path = $$(HOME)/local/lib
@
to a path of your choice.In the 2nd project edit the file simpleqmlapp/qml/simpleqmlapp/qmldir so that the path matches what you set in the .pro file above. By default it contains:
@
plugin zapbsqmlplugin /home/sean_harmer/local/lib
@With the above mods in place, just do:
@
qmake
make
make install
@in the busyindicator project. Followed by:
@
qmake
make
@in the simpleqmlapp project.