QDeclarativeExtensionPlugin与QML通信

时间:2011-06-23 17:20:09

标签: c++ qt4 qml meego

我正在编写一个MeeGo Process查看器应用程序,我无法进行QML和c ++通信。

课程概述

  • 列表项 - Q_OBJECT并由列表模型使用
  • 列表模型 - 此类实现QAbstractListModel
  • 插件 - 此类从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”

import com.int.component 1.0

感谢您阅读此内容!
凯尔

1 个答案:

答案 0 :(得分:3)

我认为这video可以帮到你。这是一个很好的教程,展示了如何集成c ++和QML。

通常你不应该弄乱 .pro 文件,但你必须在 .qmlproject 文件中添加importPaths: [ ...]指令。

另一方面,您似乎使用Q_EXPORT_PLUGIN2(Proc, ProcPlugin)导出插件,但我在QML文件中看不到任何import Proc 1.0 ...