Create QML Plugin (type not created)



  • Hi!
    I created plugin using Poppler lib, but it does not work

    pro:
    @TEMPLATE = lib
    CONFIG += qt plugin
    QT += declarative

    LIBS += -L"/home/ruslan/Doc/Qt/Project/qmlPDf/libs" -lpoppler-qt4
    INCLUDEPATH += src/

    HEADERS +=
    qmlpdf.h
    qmlpdfplugin.h

    SOURCES +=
    qmlpdf.cpp
    qmlpdfplugin.cpp@

    plugin.h:
    @#ifndef QMLPDFPLUGIN_H
    #define QMLPDFPLUGIN_H

    #include <QDeclarativeExtensionPlugin>

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

    #endif // QMLPDFPLUGIN_H
    @

    plugin.cpp:
    @#include "qmlpdfplugin.h"
    #include "qmlpdf.h"

    #include <QtDeclarative>

    void qmlPDFPlugin::registerTypes(const char *uri){
    qmlRegisterType<qmlPDF>(uri,1,0,"PDFView");
    }

    Q_EXPORT_PLUGIN2(qmlpdfplugin,qmlPDFPlugin);
    @

    DeclarItem.cpp:
    @#include "qmlpdf.h"
    #include "poppler-qt4.h"

    #include <QApplication>
    #include <QDesktopWidget>
    #include <QPainter>
    #include <QFile>
    #include <QDebug>

    qmlPDF::qmlPDF(QDeclarativeItem *parent) :
    QDeclarativeItem(parent)
    {
    docPDF = Poppler::Document::load("/home/ruslan/Doc/Qt/Project/PDFViewer/jni.pdf");
    setFlag(ItemHasNoContents,false);
    }
    @

    If I delete line @docPDF = Poppler::Document::load("/home/ruslan/Doc/Qt/Project/PDFViewer/jni.pdf"); @
    my plugin is good work, but another @Project/qmlPDf/App.qml:8:5: PDFView is not a type
    PDFView {
    ^ @





  • Please! Help me!



  • I think you missed to add qmlPDF/libs directory to your LD_LIBRARY_PATH so plugin could not find poppler library, Just copy plotter library to place where your executable is. BTW (Why do you declare all member variables, used as property value storage, public? Shouldn't they be private or protected?)



  • bq. I think you missed to add qmlPDF/libs directory to your LD_LIBRARY_PATH so plugin could not find poppler library

    I added poppler library in LIBS variable
    @LIBS += -L"libs-path" -lpoppler-qt4@

    bq. Why do you declare all member variables, used as property value storage, public? Shouldn’t they be private or protected?

    Qt Quick / QML works with the meta-object system and member variables are declared in the class as public does not see



  • But it's in build time.
    When your run application (for exmaple qmlviewer) you need to set this path in LD_LIBRARY_PATH or copy this poppler library to place where qmlviewer is or other place where libraries are searched.

    @
    LIBS+= -L....
    @
    works only in build time.
    Please test with:
    LD_LIBRARY_PATH="/home/ruslan/Doc/Qt/Project/qmlPDf/libs"

    Additionally your App.qml files lacks of import.
    If your plugin binary is in the same place where App.qml is the you should add:
    @
    "import qmlPDFPlugin 1.0"
    @

    Could you please read whole documentation regarding:
    http://qt-project.org/doc/qt-4.8/declarative-tutorials-extending-chapter6-plugins.html



  • Sorry, but this not work :(



  • Ok.. this is works!
    I am build this project on Windows
    Copies libs (poppler, zlib, openjpeg, freetype) in %QTDIR%\bin


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.