Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #include <QtCore>
  2.  
  3. class Thread : public QThread
  4. {
  5. public:
  6. Thread(int m) : m(m) {}
  7.  
  8. protected:
  9. virtual void run()
  10. {
  11. sleep(m);
  12. qDebug() << m;
  13. }
  14.  
  15. private:
  16. int m;
  17. };
  18.  
  19. int main(int argc, char *argv[])
  20. {
  21. QCoreApplication a(argc, argv);
  22. QList<Thread *> list;
  23.  
  24. foreach (const QString &s, a.arguments()) {
  25. bool ok;
  26. int n = s.toInt(&ok);
  27. if (ok) {
  28. Thread *t = new Thread(n);
  29. t->start();
  30. list << t;
  31. }
  32. }
  33.  
  34. foreach (Thread *t, list)
  35. t->wait();
  36.  
  37. qDeleteAll(list);
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement