Skip to content

Commit

Permalink
simple qml plugin support
Browse files Browse the repository at this point in the history
FIXME:
1. if not plugin, qmake must run twice so that QmlAV LFLAG is ok
2. player and other types
  • Loading branch information
wang-bin committed Sep 2, 2013
1 parent 2e695dd commit 77fd525
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 20 deletions.
1 change: 0 additions & 1 deletion examples/QMLPlayer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ int main(int argc, char *argv[])
QGuiApplication app(argc, argv);

QtQuick2ApplicationViewer viewer;
qmlRegisterType<QQuickItemRenderer>("QtAV", 1, 0, "QQuickItemRenderer");
QString qml = "qml/QMLPlayer/main.qml";
if (!QFile(qml).exists())
qml.prepend("qrc:///");
Expand Down
2 changes: 1 addition & 1 deletion examples/examples.pro
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ config_gl {
}

greaterThan(QT_MAJOR_VERSION, 4):qtHaveModule(quick) {
# SUBDIRS += QMLPlayer
SUBDIRS += QMLPlayer
}
22 changes: 13 additions & 9 deletions qml/libQmlAV.pri
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ NAME = QmlAV
error("lib$${NAME}.pri already included")
unset(NAME)
}
#!isEmpty(LIBQTAV_PRI_INCLUDED):error("libQtAV.pri already included")
eval(LIB$$upper($$NAME)_PRI_INCLUDED = 1)

LIB_VERSION = 1.2.3 #0.x.y may be wrong for dll
Expand All @@ -69,16 +68,16 @@ PROJECT_LIBDIR = $$qtLongName($$BUILD_DIR/lib)
} else {
QMAKE_CXXFLAGS += -isystem $$PROJECT_SRCPATH -isystem $$PROJECT_SRCPATH/..
}
INCLUDEPATH *= $$PROJECT_SRCPATH $$PROJECT_SRCPATH/.. $$PROJECT_SRCPATH/QmlAV
INCLUDEPATH *= $$PROJECT_SRCPATH $$PROJECT_SRCPATH/.. $$PROJECT_SRCPATH/$$NAME
DEPENDPATH *= $$PROJECT_SRCPATH
QMAKE_LFLAGS_RPATH += #will append to rpath dir

#eval() ?
#!qtav-buildlib {
!contains(CONFIG, $$lower($$NAME)-buildlib) {
CONFIG(plugin) {
#The following may not need to change
CONFIG *= link_prl
LIBS *= -L$$PROJECT_LIBDIR -l$$qtLibName($$NAME)
CONFIG *= link_prl
LIBS *= -L$$PROJECT_LIBDIR -l$$qtLibName($$NAME)
isEqual(STATICLINK, 1) {
PRE_TARGETDEPS += $$PROJECT_LIBDIR/$$qtStaticLib($$NAME)
} else {
Expand All @@ -97,18 +96,20 @@ QMAKE_LFLAGS_RPATH += #will append to rpath dir
}
}
}
}
} else {
#Add your additional configuration first. e.g.

# win32: LIBS += -lUser32
# The following may not need to change
DESTDIR= $$PROJECT_LIBDIR

#TEMPLATE = lib
VERSION = $$LIB_VERSION
#TEMPLATE = lib
!CONFIG(plugin):VERSION = $$LIB_VERSION
TARGET = $$PROJECT_TARGETNAME ##I commented out this before, why?
DESTDIR= $$PROJECT_LIBDIR

CONFIG *= create_prl #
CONFIG *= create_prl #
isEqual(STATICLINK, 1) {
CONFIG -= shared dll ##otherwise the following shared is true, why?
CONFIG *= staticlib
Expand All @@ -118,9 +119,12 @@ QMAKE_LFLAGS_RPATH += #will append to rpath dir
}

shared {
CONFIG(plugin) {
!isEqual(DESTDIR, $$BUILD_DIR/bin/QtAV): DLLDESTDIR = $$BUILD_DIR/bin/QtAV
} else {
!isEqual(DESTDIR, $$BUILD_DIR/bin): DLLDESTDIR = $$BUILD_DIR/bin #copy shared lib there
CONFIG(release, debug|release): !isEmpty(QMAKE_STRIP): QMAKE_POST_LINK = -$$QMAKE_STRIP $$PROJECT_LIBDIR/$$qtSharedLib($$NAME)

}
#copy from the pro creator creates.
symbian {
MMP_RULES += EXPORTUNFROZEN
Expand Down
16 changes: 12 additions & 4 deletions qml/libQmlAV.pro
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
TEMPLATE = lib
CONFIG += qt plugin
TARGET = QmlAV
QT += quick

QT += quick qml

CONFIG *= qmlav-buildlib

#var with '_' can not pass to pri?
STATICLINK = 0
PROJECTROOT = $$PWD/..
!include($$PROJECTROOT/src/libQtAV.pri): error("could not find libQtAV.pri")
!include(libQmlAV.pri): error("could not find libQmlAV.pri")
preparePaths($$OUT_PWD/../out)
!include($$PROJECTROOT/src/libQtAV.pri): error("could not find libQtAV.pri")

RESOURCES +=
message($$BUILD_DIR)
plugin.files = $$PWD/qmldir
plugin.path = $$BUILD_DIR/bin/QtAV #TODO: Qt install dir
plugin.commands = -\$\(COPY_FILE\) $$shell_path($$plugin.files) $$shell_path($$plugin.path)
OTHER_FILES += $$plugin.files

QMAKE_POST_LINK += $$plugin.commands

win32 {
RC_FILE = #$${PROJECTROOT}/res/QtAV.rc
Expand All @@ -37,7 +44,8 @@ OTHER_FILES += $$RC_FILE
#UINT64_C: C99 math features, need -D__STDC_CONSTANT_MACROS in CXXFLAGS
DEFINES += __STDC_CONSTANT_MACROS

SOURCES += QQuickItemRenderer.cpp
SOURCES += QQuickItemRenderer.cpp \
plugin.cpp
HEADERS += QmlAV/private/QQuickItemRenderer_p.h
SDK_HEADERS += QmlAV/QQuickItemRenderer.h

Expand Down
21 changes: 21 additions & 0 deletions qml/plugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <QtQml/QQmlExtensionPlugin>
#include <QtQml/qqml.h>
#include <QmlAV/QQuickItemRenderer.h>

namespace QtAV {

class QtAVQmlPlugin : public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")

public:
void registerTypes(const char *uri)
{
Q_ASSERT(uri == QLatin1String("QtAV"));
qmlRegisterType<QQuickItemRenderer>(uri, 1, 0, "QQuickItemRenderer");
}
};
} //namespace QtAV

#include "plugin.moc"
2 changes: 2 additions & 0 deletions qml/qmldir
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module QtAV
plugin QmlAV
7 changes: 2 additions & 5 deletions src/libQtAV.pri
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ NAME = QtAV
error("lib$${NAME}.pri already included")
unset(NAME)
}
#!isEmpty(LIBQTAV_PRI_INCLUDED):error("libQtAV.pri already included")
eval(LIB$$upper($$NAME)_PRI_INCLUDED = 1)

LIB_VERSION = 1.2.3 #0.x.y may be wrong for dll
Expand All @@ -63,22 +62,20 @@ CONFIG += depend_includepath #?

PROJECT_SRCPATH = $$PWD
PROJECT_LIBDIR = $$qtLongName($$BUILD_DIR/lib)

#for system include path
*msvc* {
} else {
QMAKE_CXXFLAGS += -isystem $$PROJECT_SRCPATH -isystem $$PROJECT_SRCPATH/..
}
INCLUDEPATH *= $$PROJECT_SRCPATH $$PROJECT_SRCPATH/.. $$PROJECT_SRCPATH/QtAV
INCLUDEPATH *= $$PROJECT_SRCPATH $$PROJECT_SRCPATH/.. $$PROJECT_SRCPATH/$$NAME
DEPENDPATH *= $$PROJECT_SRCPATH
QMAKE_LFLAGS_RPATH += #will append to rpath dir

#eval() ?
#!qtav-buildlib {
!contains(CONFIG, $$lower($$NAME)-buildlib) {
#The following may not need to change
CONFIG *= link_prl
LIBS *= -L$$PROJECT_LIBDIR -l$$qtLibName($$NAME)
LIBS *= -L$$PROJECT_LIBDIR -l$$qtLibName($$NAME)
isEqual(STATICLINK, 1) {
PRE_TARGETDEPS += $$PROJECT_LIBDIR/$$qtStaticLib($$NAME)
} else {
Expand Down

0 comments on commit 77fd525

Please sign in to comment.