我正在编写一个 MeeGo Process 查看器应用程序,但无法让 QML 和 c++ 进行通信。
类概述
- 列表项 - 一个 Q_OBJECT 并由列表模型使用
- 列表模型 - 此类实现 QAbstractListModel
- Plugin - 此类从 QDeclarativeExtensionPlugin 实现,用于创建 QML 可以使用的库。
#include <QtDeclarative> #include <QtDeclarative/qdeclarative.h> void ProcPlugin::registerTypes(const char *uri) { qmlRegisterType<ListModel>(uri, 1, 0,"listmodel"); } Q_EXPORT_PLUGIN2(Proc, ProcPlugin)
项目文件(我认为这是问题所在)
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
}
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 { }
}
}
错误信息
main.qml:3:1:未安装模块“com.int.component”
导入 com.int.component 1.0
感谢您阅读到这里!
凯尔