printerthreadhandle.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. #include "printerthreadhandle.h"
  2. #include "globalinfo.h"
  3. #include "handle/printer/boxtemlateone.h"
  4. PrinterThreadHandle::PrinterThreadHandle(QObject *parent) : QObject(parent),manger(nullptr),thread(nullptr)
  5. {
  6. }
  7. void PrinterThreadHandle::updateConfig()
  8. {
  9. if(manger == nullptr) return;
  10. auto config = GlobalInfo::this_()->config();
  11. manger->setPrinterName(config->printerName);
  12. }
  13. void PrinterThreadHandle::start()
  14. {
  15. if(thread == nullptr){
  16. thread = new QThread(this);
  17. connect(thread,&QThread::started,this,&PrinterThreadHandle::updateConfig);
  18. manger = new PrinterManger(this);
  19. connect(this,&PrinterThreadHandle::printerBox,manger,&PrinterManger::printerBox,Qt::QueuedConnection);
  20. connect(this,&PrinterThreadHandle::printerPack,manger,&PrinterManger::printerPack,Qt::QueuedConnection);
  21. auto config = GlobalInfo::this_()->config();
  22. connect(config,&ConfigInfo::configUpdate,this,&PrinterThreadHandle::updateConfig,Qt::QueuedConnection);
  23. manger->setPrinter(QSharedPointer<BaseBoxPrinter>(new BoxTemlateOne()),QSharedPointer<BasePackinfoPrinter>(new PackTemlateOne()));
  24. this->moveToThread(thread);
  25. thread->start();
  26. }
  27. }