Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #include "MainWindow.h"
  2.  
  3. MainWindow::MainWindow(QWidget *parent)
  4. : QMainWindow(parent)
  5. {
  6. ui.setupUi(this);
  7. QObject::connect(this->ui.pushbutton, SIGNAL(clicked()), this, SLOT(process()));
  8. }
  9.  
  10. void MainWindow::process()
  11. {
  12. ListCalc m_Calcul(ui.qprogressbar);
  13. auto thread = new QThread();
  14. m_Calcul->moveToThread(thread);
  15. m_Calcul.process(); // This is the action I would like to put in a thread !
  16. }
  17.  
  18. #include "ListCalc.h"
  19.  
  20. using namespace std;
  21.  
  22. namespace Ui {
  23. class MainWindow;
  24. }
  25.  
  26. class MainWindow : public QMainWindow
  27. {
  28. Q_OBJECT
  29.  
  30. private:
  31. Ui::MainWindowClass ui;
  32.  
  33. public:
  34. MainWindow(QWidget *parent = Q_NULLPTR);
  35. ListCalc m_Calcul;
  36.  
  37. private slots:
  38. void process();
  39. };
  40.  
  41. #include "ListCalc.h"
  42.  
  43. ListCalc::ListCalc(QProgressBar* bar) :
  44. m_Bar(bar)
  45. {
  46.  
  47. }
  48.  
  49. ListCalc::~ListCalc()
  50. {
  51.  
  52. }
  53.  
  54. void ListCalc::process()
  55. {
  56. auto size = 30000;
  57. for (auto i = 0;i < size;++i)
  58. {
  59. m_Bar->setValue(i / size * 100);
  60. std::cout<<"1"<<std::endl;
  61. }
  62. }
  63.  
  64. class ListCalc : public QObject
  65. {
  66. Q_OBJECT
  67.  
  68. public:
  69. ListCalc(QProgressBar*);
  70. ~ListCalc();
  71.  
  72. private:
  73. QProgressBar* m_Bar;
  74. public slots:
  75. void process();
  76.  
  77. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement