QDeclarativeExtensionPlugin communicating with QML
I am Writing a MeeGo Process viewer application, and I am having trouble getting the QML and the c++ communicating.
Class Overview
- List Item - A Q_OBJECT and used by the List Model
- List Model - This Class implements QAbstractListModel
- Plugin - This class implements from QDeclarativeExtensionPlugin and is used for creating a library that the QML can use.
#include <QtDeclarative> #include <QtDeclarative/qdeclarative.h> void ProcPlugin::registerTypes(const char *uri) { qmlRegisterType<ListModel>(uri, 1, 0,"listmodel"); } Q_EXPORT_PLUGIN2(Proc, ProcPlugin)
Project File (I Think This is the problem)
TEMPLATE = lib
TARGET = proc
QT += declarative
CONFIG += qt plugin
TARGET = $$qtLibraryTarget($$TARGET)
uri = com.int.components
# Input
SOURCES += \
proc_plugin.cpp \
listmodel.cpp \
listitem.cpp \
main.cpp \
process.cpp \
updatedaemon.cpp
HEADERS += \
proc_plugin.h \
listmodel.h \
listitem.h \
process.h \
updatedaemon.h
OTHER_FILES = qmldir \
qtc_packaging/meego.spec \
proc.pro.user \
Proc_view.svg
!equals(_PRO_FILE_PWD_, $$OUT_PWD) {
copy_qmldir.target = $$OUT_PWD/qmldir
copy_qmldir.depends = $$_PRO_FILE_PWD_/qmldir
copy_qmldir.commands = $(COPY_FILE) \"$$replace(copy_qmldir.depends, /, $$QMAKE_DIR_SEP)\" \"$$replace(copy_qmldir.target, /, $$QMAKE_DIR_SEP)\"
QMAKE_EXTRA_TARGETS += copy_qmldir
PRE_TARGETDEPS += $$copy_qmldir.target
}
qmldir.files = qmldir
symbian {
# ...
} else:unix {
installPath = /usr/lib/qt4/imports/$$replace(uri, \\., /)
qmldir.path = $$installPath
target.path = $$installPath
INSTALLS += target qmldir
}
The QML
import QtQuick 1.0
import "ColumnHelper.js" as ColumnHelper
import com.int.component 1.0
Rectangle {
id:big_papa
width: 680
height: 200
ListView {
id: processView
model: processModel
property variant columnWidths: ColumnHelper.calcColumnWidths(model, processView)
anchors.top开发者_开发问答: name.bottom
anchors.topMargin: name.height
anchors.fill: parent
delegate: ProcessItem { }
}
}
The error message
main.qml:3:1: module "com.int.component" is not installed
import com.int.component 1.0
Thanks for reading this far!
KyleI think this video could help you. It a nice tutorial showing how to integrate c++ and QML.
Normally you shouldn't have to mess with the .pro file but you have to add an importPaths: [ ...]
directive in the .qmlproject file.
On the other hand it seems that you export you plugin with Q_EXPORT_PLUGIN2(Proc, ProcPlugin)
but I don't see any import Proc 1.0
in you QML file ...
精彩评论