diff --git a/src/lpCoreCtrl/CoreCtrl.cpp b/src/lpCoreCtrl/CoreCtrl.cpp index f466103..f0b496d 100644 --- a/src/lpCoreCtrl/CoreCtrl.cpp +++ b/src/lpCoreCtrl/CoreCtrl.cpp @@ -8,7 +8,7 @@ #include "lpCameraConfig.h" #include "lpCoreConfig.h" #include "ImageObject.h" - +#include "QFunctionTransfer.h" TPCORECTRL_API ICoreCtrl* Lib_CoreCtrl_Init(void) { CCoreCtrl* gpCoreCtrl = nullptr; @@ -33,6 +33,7 @@ CCoreCtrl::CCoreCtrl(void) { lpCoreConfig::instance()->readConfig(); lpCameraConfig::instance(); + QFunctionTransfer::Instance(); m_camDevManager = new CCameraPool();//相机管理 ((CCameraPool*)m_camDevManager)->InitPool(); diff --git a/src/lpCoreCtrl/ImageObject.cpp b/src/lpCoreCtrl/ImageObject.cpp index 2417cfc..d57ea42 100644 --- a/src/lpCoreCtrl/ImageObject.cpp +++ b/src/lpCoreCtrl/ImageObject.cpp @@ -2,6 +2,7 @@ #include "CoreCtrl.h" #include "zfunctions.h" #include "callbackFunc.h" +#include "QFunctionTransfer.h" CImageObject::CImageObject(class CCoreCtrl* pCoreCtrl) : m_pCoreCtrl(pCoreCtrl) @@ -237,11 +238,14 @@ IAlgorithmShared* CImageObject::IGetShared() void CImageObject::IVariantMapToUI(const QVariantMap& vMap) { + QString strSerial = m_pCamImg->Serial(); - if (lpCallBackFunc::instance()->m_ResultCallBackFunc) - { - lpCallBackFunc::instance()->m_ResultCallBackFunc(m_pCamImg->Serial(), vMap); - } + QFunctionTransfer::Instance()->execInMain([this, strSerial, vMap]() { + if (lpCallBackFunc::instance()->m_ResultCallBackFunc) + { + lpCallBackFunc::instance()->m_ResultCallBackFunc(strSerial, vMap); + } + }); } const ZStringA& CImageObject::ICameraSerial() diff --git a/src/lpCoreCtrl/tpCamera/CameraPool.cpp b/src/lpCoreCtrl/tpCamera/CameraPool.cpp index 747572f..f63005e 100644 --- a/src/lpCoreCtrl/tpCamera/CameraPool.cpp +++ b/src/lpCoreCtrl/tpCamera/CameraPool.cpp @@ -2,6 +2,7 @@ #include #include "callbackFunc.h" #include "lpCameraConfig.h" +#include "QFunctionTransfer.h" CCameraPool::CCameraPool(void) : m_libs("") @@ -649,10 +650,15 @@ int CCameraPool::IPushCameraData(ICameraObject* pCamObj) // } // else { - if (lpCallBackFunc::instance()->m_ImageCallBackFunc) - { - lpCallBackFunc::instance()->m_ImageCallBackFunc(pImage->Serial(), pImage->ToQImage()); - } + QString strSerial = pImage->Serial(); + QImage showImg = pImage->ToQImage(); + QFunctionTransfer::Instance()->execInMain([this, strSerial, showImg]() { + if (lpCallBackFunc::instance()->m_ImageCallBackFunc) + { + lpCallBackFunc::instance()->m_ImageCallBackFunc(strSerial, showImg); + } + }); + try { //获取算法参数 绑定到图像 if (lpCallBackFunc::instance()->m_GetVariantCallBackFunc) diff --git a/tpvs17/lpCoreCtrl/QFunctionTransfer.h b/tpvs17/lpCoreCtrl/QFunctionTransfer.h new file mode 100644 index 0000000..525b9d7 --- /dev/null +++ b/tpvs17/lpCoreCtrl/QFunctionTransfer.h @@ -0,0 +1,32 @@ +#ifndef _H_QFUNCTIONTRANSFER_H_ +#define _H_QFUNCTIONTRANSFER_H_ + +#include +#include + +class QFunctionTransfer : public QObject +{ + Q_OBJECT + +public: + explicit QFunctionTransfer(QObject *parent = 0) { + qRegisterMetaType>("std::tr1::function"); + connect(this, &QFunctionTransfer::comming, this, &QFunctionTransfer::exec, Qt::QueuedConnection); + }; + void execInMain(std::tr1::function f) { + emit this->comming(f); + }; + static QFunctionTransfer* Instance() { + static QFunctionTransfer ins; + return &ins; + } +signals: + void comming(std::tr1::function f); +public slots: + void exec(std::tr1::function f) + { + f(); + }; +}; + +#endif diff --git a/tpvs17/lpCoreCtrl/lpCoreCtrl.vcxproj b/tpvs17/lpCoreCtrl/lpCoreCtrl.vcxproj index a9c4fb9..b86b9eb 100644 --- a/tpvs17/lpCoreCtrl/lpCoreCtrl.vcxproj +++ b/tpvs17/lpCoreCtrl/lpCoreCtrl.vcxproj @@ -26,14 +26,30 @@ true + + true + true + + true + + + $(QTDIR)\bin\moc.exe;%(FullPath) + Moc%27ing %(Identity)... + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + "$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -DUNICODE -D_UNICODE -DWIN32 -DWIN64 -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_SERIALPORT_LIB -DQT_SQL_LIB -DTPCORECTRL_LIB -DTPCORECTRL_EXPORTS -D%(PreprocessorDefinitions) "-I.\GeneratedFiles" "-I." "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)" "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtNetwork" "-I$(QTDIR)\include\QtSerialPort" "-I$(QTDIR)\include\QtSql" "-I.\..\..\src\lpCoreCtrl" "-I.\..\..\src\lpCoreCtrl\tpCamera" "-I.\..\..\src\lpCoreCtrl\tpImgProc" "-I.\..\..\3part\libzkq\include" "-I.\..\..\3part\openssl\include" "-I.\..\..\3part\tadpole\include\tpBase" + $(QTDIR)\bin\moc.exe;%(FullPath) + Moc%27ing %(Identity)... + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + "$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -DUNICODE -D_UNICODE -DWIN32 -DWIN64 -DQT_NO_DEBUG -DNDEBUG -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_SERIALPORT_LIB -DQT_SQL_LIB -DTPCORECTRL_LIB -DTPCORECTRL_EXPORTS -D%(PreprocessorDefinitions) "-I.\GeneratedFiles" "-I." "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)" "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtNetwork" "-I$(QTDIR)\include\QtSerialPort" "-I$(QTDIR)\include\QtSql" "-I.\..\..\src\lpCoreCtrl" "-I.\..\..\src\lpCoreCtrl\tpCamera" "-I.\..\..\src\lpCoreCtrl\tpImgProc" "-I.\..\..\3part\libzkq\include" "-I.\..\..\3part\openssl\include" "-I.\..\..\3part\tadpole\include\tpBase" + $(QTDIR)\bin\moc.exe;%(FullPath) Moc%27ing %(Identity)... @@ -57,6 +73,10 @@ + + + + {784071A9-BF94-4D27-B62E-588ACD7E0633} Qt4VSv1.0 diff --git a/tpvs17/lpCoreCtrl/lpCoreCtrl.vcxproj.filters b/tpvs17/lpCoreCtrl/lpCoreCtrl.vcxproj.filters index 50382b5..16e291e 100644 --- a/tpvs17/lpCoreCtrl/lpCoreCtrl.vcxproj.filters +++ b/tpvs17/lpCoreCtrl/lpCoreCtrl.vcxproj.filters @@ -80,6 +80,12 @@ Generated Files + + Generated Files + + + Generated Files + @@ -129,5 +135,16 @@ Header Files + + Header Files + + + + + Generated Files + + + Generated Files + \ No newline at end of file