//==========================================================
//qml.qrc
<RCC>
<qresource prefix="/ui">
<file alias="qml/qml_main">Auto_Order_UI.qml</file>
<file>images/Alert_09.png</file>
<file>images/Alert_10.png</file>
<file>images/Alert_11.png</file>
<file>images/Alert_12.png</file>
<file>images/Alert_13.png</file>
<file>images/Alert_14.png</file>
<file>images/Alert_15.png</file>
<file>images/Alert_16.png</file>
<file>images/carmageddon2.png</file>
<file>images/counter-strike.png</file>
<file>images/X3.png</file>
<file alias="qml/qml_sw">sw.qml</file>
<file>images/button.png</file>
</qresource>
</RCC>
//==========================================================
//main.cpp
#include <QtGui/QApplication>
#include "mainwindow.h"
#include <QtDeclarative/QDeclarativeView>
#include <QtDeclarative/QDeclarativeComponent>
#include <QtDeclarative/QDeclarativeItem>
#include <QtDeclarative/QDeclarativeEngine>
#include <QtDeclarative/QDeclarativeContext>
#include "numbercount.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
NumberCount *numberCount = new NumberCount();
QDeclarativeContext *context = view.rootContext();
context->setContextProperty("numberCount",numberCount);//注册C++对象到qml
view.setSource(QUrl("qrc:/ui/qml/qml_sw"));
QObject *rootObject = dynamic_cast<QObject*>(view.rootObject());
QObject::connect(numberCount, SIGNAL(resetData(QVariant)), rootObject, SLOT(resetData(QVariant)));//将C++信号与QML槽关联
view.show();
return a.exec();
}
  官方文档:
  It is possible to call methods of  QObject   derived types by either exposing the methods as public slots, or by marking the methods  Q_INVOKABLE .
  也是说 getTotal()和incre()都能在QML中访问。
  运行界面: