#ifndef COUNTDATA_H #define COUNTDATA_H #include #include "databasesql.h" #include "QSqlQuery" #pragma execution_character_set("utf-8") class CountData : public QObject { Q_OBJECT public: CountData(QObject *parent = 0){ m_pDb = NULL; }; ~CountData(){}; void setDB(class DataBaseSql *pDb){ m_pDb = pDb; }; public slots: void doWork(QVariantMap m_Map) { QMap *m_counter=new QMap(); QVariantMap m_proMap; m_proMap.insert("Type", "start"); emit sgShowProgress(m_proMap); QString result; QSqlQuery sqlCount; QSqlQuery sql; /* ... here is the expensive or blocking operation ... */ QString strSql_Count = m_Map.value("SqlCount").toString(); QString strSql_Check = m_Map.value("SqlCheck").toString(); if (m_pDb){ //m_counter->clear(); m_proMap.insert("msg", "正在获取数量..."); emit sgShowProgress(m_proMap); m_pDb->checkoutData(strSql_Count, sqlCount); //emit sgShowMsg("正在查询数据"); int sum = 0; int m_size = 0; while (sqlCount.next()) { m_size = sqlCount.value(0).toInt(); } QString strname = QString("select model,count(model) from (%1) GROUP BY model ;").arg(strSql_Check); m_pDb->checkoutData(strname, sql); //m_pDb->checkoutData(strSql_Check, sql); //emit sgShowMsg("正在统计中"); m_proMap.remove("msg"); m_proMap.insert("msg", QString("共%1条记录,正在分类核算数据,请稍后").arg(m_size)); emit sgShowProgress(m_proMap); while (sql.next()) { /*这里下面是统计查询到的通道对应的产品总数*/ QString model = sql.value(0).toString(); int nValue = sql.value(1).toInt(); if (m_counter->contains(model)) { (*m_counter)[model]++; } else { m_counter->insert(model, nValue); } } result = QString("%1").arg(m_size); emit sgShowMsg("统计完成"); } m_proMap.remove("Type"); m_proMap.insert("Type", "stop"); emit sgShowProgress(m_proMap); emit resultReady(result, m_counter); } signals: void resultReady(const QString &result, const QMap *p); void sgShowMsg(QString str); void sgShowProgress(QVariantMap m_map); private: class DataBaseSql *m_pDb; }; #endif // COUNTDATA_H