{"id":202312,"date":"2013-11-18T15:35:03","date_gmt":"2013-11-18T11:35:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=202312"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=202312","title":{"rendered":"<span class=\"post_title\">Qt: \u0448\u0430\u0431\u043b\u043e\u043d \u0434\u043b\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u0412\u0441\u0435\u043c \u0445\u0430\u0431\u0440\u0430\u043f\u0440\u0438\u0432\u0435\u0442!<br \/>  \u041a\u0430\u043a-\u0442\u043e \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u043b\u043e\u0441\u044c \u043c\u043d\u0435 \u0432 Qt 5.1.1 \u0434\u043b\u044f WinXP \u0432 VS2009 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441 \u0438\u043d\u0442\u0435\u043d\u0441\u0438\u0432\u043d\u044b\u043c \u043e\u0431\u043c\u0435\u043d\u043e\u043c \u0441\u0438\u0433\u043d\u0430\u043b\u0430\u043c\u0438. \u0412\u0437\u044f\u043b \u044f <a href=\"http:\/\/www.labirint.ru\/books\/272473\/\">\u0428\u043b\u0435\u0435<\/a>, \u0432\u044b\u0447\u0438\u0442\u0430\u043b \u0443 \u043d\u0435\u0433\u043e, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u043e\u0442 QThread \u0438 \u2014 \u0432\u0443\u0430\u043b\u044f, \u0432\u0435\u043b\u043a\u043e\u043c \u0432 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c! \u041d\u0430 \u0432\u0441\u044f\u043a\u0438\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 \u0437\u0430\u0433\u043b\u044f\u043d\u0443\u043b \u0432 <a href=\"http:\/\/qt-project.org\/doc\/qt-5.1\/qtcore\/qthread.html#details\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e Qt<\/a> \u2014 \u0442\u0430\u043c \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u0432\u043e\u0437\u0440\u0430\u0436\u0430\u043b \u043f\u0440\u043e\u0442\u0438\u0432 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0442 QThread \u0441\u0432\u043e\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430. \u041d\u0443 \u0447\u0442\u043e \u0436\u0435 \u2014 \u043f\u043e\u0440\u044f\u0434\u043e\u043a, \u0441\u0434\u0435\u043b\u0430\u043d\u043e! \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u044e \u2014 \u0432\u0440\u043e\u0434\u0435 \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u043e \u043a\u0430\u043a-\u0442\u043e \u043d\u0435 \u0442\u0430\u043a\u2026 \u041d\u0430\u0447\u0438\u043d\u0430\u044e \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u043e\u0442\u043b\u0430\u0434\u043a\u0438 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u2014 \u0430 \u0442\u0430\u043c \u0442\u0432\u043e\u0440\u0438\u0442\u0441\u044f \u0447\u0435\u0440\u0442 \u0437\u043d\u0430\u0435\u0442 \u0447\u0442\u043e! \u0422\u043e \u0441\u0438\u0433\u043d\u0430\u043b\u044b \u043d\u0435 \u0432\u044b\u0445\u043e\u0434\u044f\u0442, \u0442\u043e \u0432\u044b\u0445\u043e\u0434\u044f\u0442, \u043d\u043e \u043a\u0430\u043a-\u0442\u043e \u043a\u0440\u0438\u0432\u043e \u0438 \u0438\u0437 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430. \u041e\u0434\u043d\u0438\u043c \u0441\u043b\u043e\u0432\u043e\u043c, \u043f\u043e\u043b\u043d\u044b\u0439 \u0431\u0430\u0440\u0434\u0430\u043a! \u041f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043e\u0441\u043d\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e-google-\u0438\u0442\u044c \u0438 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u0442\u0435\u043c\u0435 (\u043c\u043d\u0435 \u043f\u043e\u043c\u043e\u0433\u043b\u0438 \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/vasinnet.blogspot.com\/2012\/08\/recommended-way-to-using-qthread.html\">\u0442\u0443\u0442<\/a>, <a href=\"http:\/\/habrahabr.ru\/post\/150274\/\">\u0437\u0434\u0435\u0441\u044c<\/a> \u0438 <a href=\"http:\/\/qt-project.org\/wiki\/Threads_Events_QObjects\">\u0442\u0430\u043c<\/a>). \u0412 \u0438\u0442\u043e\u0433\u0435 \u044f \u0441\u0434\u0435\u043b\u0430\u043b \u0448\u0430\u0431\u043b\u043e\u043d \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0430 \u0421++ (\u0432\u0435\u0440\u043d\u0435\u0435, \u0446\u0435\u043b\u0443\u044e \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044e \u043e\u043d\u044b\u0445), \u0447\u0442\u043e \u043c\u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b\u043e \u0432 \u0438\u0442\u043e\u0433\u0435 \u043f\u0438\u0441\u0430\u0442\u044c (\u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e) \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043a\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430, \u0436\u0438\u0432\u0443\u0449\u0435\u0433\u043e \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0438 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h4>\u0427\u0435\u0433\u043e \u0445\u043e\u0447\u0435\u0442\u0441\u044f<\/h4>\n<p>  \u0421\u0442\u0440\u0435\u043c\u0438\u043b\u0441\u044f \u044f \u043a\u043e \u0432\u043f\u043e\u043b\u043d\u0435 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u043c \u0432\u0435\u0449\u0430\u043c:  <\/p>\n<ul>\n<li>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u044b \u0421++ \u0432\u043e \u0432\u0441\u0435\u0439 \u0438\u0445 \u043a\u0440\u0430\u0441\u0435 \u2014 \u0442. \u0435. \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0432\u044b\u0437\u044b\u0432\u0430\u043b\u0441\u044f \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043f\u043e\u0442\u043e\u043a\u0430 \u0438 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043f\u0435\u0440\u0435\u0434 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u0435\u043c;<\/li>\n<li>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 Qt \u0432\u043e \u0432\u0441\u0435\u0439 \u0435\u0433\u043e \u043a\u0440\u0430\u0441\u0435 \u2014 \u0442. \u0435. \u0441\u0438\u0433\u043d\u0430\u043b\u044c\u043d\u043e-\u0441\u043b\u043e\u0442\u043e\u0432\u044b\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f, \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0438 \u043f\u0440.;<\/li>\n<li>\u043f\u0440\u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0438 \u2014 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044c \u043d\u0430\u0434 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u2014 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442 \u043f\u043e\u0442\u043e\u043a\u0430, \u0441\u043b\u043e\u0442 \u043e \u043d\u0430\u0447\u0430\u043b\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u0438 \u0441\u0438\u0433\u043d\u0430\u043b \u043e\u0431 \u044d\u043a\u0441\u0442\u0440\u0435\u043d\u043d\u043e\u043c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438;<\/li>\n<li>\u043c\u0438\u043d\u0438\u043c\u0443\u043c \u043f\u0438\u0441\u0430\u043d\u0438\u043d\u044b \u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0441\u0442\u0438.<\/li>\n<\/ul>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0443 \u043c\u0435\u043d\u044f \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435:<\/p>\n<pre><code>class SomeJob: public QObject { \tQ_OBJECT public: \tSomeJob ()\t{ \/* ... *\/ }\t\/\/ \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u043e\u0442\u043e\u043a\u0430 \t~SomeJob ()\t{ \/* ... *\/ }\t\/\/ \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0442\u043e\u043a\u0430 signals: \tvoid finished ();\t\/\/ \u043f\u043e\u0442\u043e\u043a \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b \u0441\u0432\u043e\u044e \u0440\u0430\u0431\u043e\u0442\u0443 public slots: \tvoid to_terminate ()\t{ \/* ... *\/ }\t\/\/ \u044d\u043a\u0441\u0442\u0440\u0435\u043d\u043d\u043e\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 };  ...  ThreadedObject&lt;SomeJob&gt; thr;\t\/\/ \u043e\u0431\u044a\u0435\u043a\u0442-\u0432\u043b\u0430\u0434\u0435\u043b\u0435\u0446 \u043f\u043e\u0442\u043e\u043a\u0430 thr.start ();\t\/\/ \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u043e\u0442\u043e\u043a\u0430 \u0441 \u0430\u0432\u0442\u043e\u0437\u0430\u043f\u0443\u0441\u043a\u043e\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 <\/code><\/pre>\n<p>  \u041a\u0440\u0430\u0441\u043e\u0442\u0435\u043d\u044c!<\/p>\n<h4>\u041a\u0430\u043a \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c<\/h4>\n<p>  \u0412 Qt 5.1 \u0434\u043b\u044f \u043d\u0430\u0448\u0438\u0445 \u0446\u0435\u043b\u0435\u0439 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 QThread. \u041f\u0440\u043e \u043d\u0435\u0433\u043e <a href=\"http:\/\/qt-project.org\/doc\/qt-5.1\/qtcore\/qthread.html\">\u0441\u043a\u0430\u0437\u0430\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435<\/a>: \u00ab\u043a\u043b\u0430\u0441\u0441 QThread \u0434\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u043e-\u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u043c \u0432\u0438\u0434\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438\u00bb. \u0417\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043a\u043d\u0438\u0433\u0430 \u0443 \u0428\u043b\u0435\u0435, \u043d\u043e \u0432\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438 \u0443 \u043d\u0435\u0433\u043e \u0432\u044b\u0448\u0435\u043b \u043e\u0447\u0435\u043d\u044c \u0441\u0431\u0438\u0432\u0430\u044e\u0449\u0438\u043c \u0441 \u0442\u043e\u043b\u043a\u0443: \u043e\u043d \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 <i>\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c<\/i> \u043a\u043b\u0430\u0441\u0441 QThread, \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434 run () \u0438 \u0432 \u043d\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443. \u042d\u0442\u043e \u043d\u0435\u043f\u043b\u043e\u0445\u043e \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u0432 \u0441\u0442\u0438\u043b\u0435 \u00ab\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0438, \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b\u0438\u00bb, \u043d\u043e \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0435\u043f\u0440\u0438\u0435\u043c\u043b\u0435\u043c\u043e \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432.<br \/>  \u0412 \u043e\u0431\u0449\u0435\u043c, \u0437\u0440\u044f \u044f \u0435\u0433\u043e <s>\u043f\u043e\u0441\u043b\u0443\u0448\u0430\u043b<\/s> \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043b, \u043d\u0430\u0434\u043e \u0431\u044b\u043b\u043e \u0441\u0440\u0430\u0437\u0443 \u0432\u043d\u0438\u043a\u0430\u0442\u044c \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e. \u0410 \u0432 \u043d\u0435\u0439 \u0435\u0441\u0442\u044c, \u043c\u0435\u0436\u0434\u0443 \u043f\u0440\u043e\u0447\u0438\u043c, \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440. \u041e\u043d \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u043f\u0443\u0442\u044c: <a href=\"http:\/\/qt-project.org\/doc\/qt-5.1\/qtcore\/qobject.html#moveToThread\">\u0444\u0443\u043d\u043a\u0446\u0438\u044e QObject::moveToThread (QThread *thread)<\/a>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u0442 <i>\u0440\u043e\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u044c<\/i> (\u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e? \u2014 \u0430\u043d\u0433\u043b. affinity) \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0438 \u0432\u0441\u0435\u0445 \u0435\u0433\u043e \u043f\u0440\u0435\u0434\u043a\u043e\u0432 \u043f\u043e\u0442\u043e\u043a\u0443 thread.<br \/>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0435\u043d\u0438\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:  <\/p>\n<ol>\n<li>\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u043e\u0442\u043e\u043a\u0430 \u2014 \u043a\u043b\u0430\u0441\u0441 QThread;<\/li>\n<li>\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0438 \u043f\u0435\u0440\u0435\u043d\u043e\u0441 \u0435\u0433\u043e \u0432 \u043d\u043e\u0432\u044b\u0439 \u043f\u043e\u0442\u043e\u043a;<\/li>\n<li>\u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0441\u0438\u0433\u043d\u0430\u043b\u044c\u043d\u043e-\u0441\u043b\u043e\u0442\u043e\u0432\u044b\u0445 \u0441\u0432\u044f\u0437\u0435\u0439;<\/li>\n<li>\u0437\u0430\u043f\u0443\u0441\u043a \u043f\u043e\u0442\u043e\u043a\u0430 \u0441 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u043c \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c.<\/li>\n<\/ol>\n<p>  \u0412\u0440\u043e\u0434\u0435 \u0431\u044b \u0432\u0441\u0435 \u0445\u043e\u0440\u043e\u0448\u043e, \u043d\u043e \u2014 \u043f\u043e\u043c\u043d\u0438\u0442\u0435? \u2014 \u044f \u0445\u043e\u0447\u0443, \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043b\u0441\u044f <i>\u0432 \u043d\u043e\u0432\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435<\/i>. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0437\u0430\u043f\u0443\u0449\u0435\u043d <i>\u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u043e\u0442\u043e\u043a\u0430<\/i>. \u041c\u043e\u0436\u043d\u043e \u0432\u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442, \u0430 \u043f\u043e\u0442\u043e\u043c \u043f\u043e\u0442\u043e\u043a. \u041d\u043e \u0432\u0441\u0435, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u043e \u0432 \u0441\u0442\u0435\u043a\u0435 (\u043a\u0443\u0447\u0435) <i>\u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e <\/i>\u043f\u043e\u0442\u043e\u043a\u0430, \u0430 \u043d\u0435 \u043d\u043e\u0432\u043e\u0433\u043e. \u041c\u043e\u0436\u043d\u043e \u043a\u0430\u043a-\u0442\u043e \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u043e \u0432\u0441\u0435 \u044d\u0442\u043e \u0445\u043e\u0437\u044f\u0439\u0441\u0442\u0432\u043e \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0442\u0438 \u0432 \u043d\u043e\u0432\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u0438 \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0432 \u0441\u0442\u0430\u0440\u043e\u043c, \u043d\u043e\u2026 \u043f\u0440\u043e\u0449\u0435 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0443\u0436\u0435 \u0432 \u043d\u043e\u0432\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435. \u0422\u0430\u043a \u0447\u0442\u043e \u0432\u043e\u0442 \u043d\u0430\u043c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u21161. \u041d\u0430\u0434\u043e \u0440\u0435\u0448\u0430\u0442\u044c.<br \/>  \u041f\u043e\u0442\u043e\u043c \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u21162. \u042f \u0441\u043e\u0437\u0434\u0430\u043b \u0441\u0438\u043c\u043f\u0430\u0442\u0438\u0447\u043d\u044b\u0439 \u0448\u0430\u0431\u043b\u043e\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d \u043e\u0442 QObject \u2014 \u044d\u0442\u043e \u043c\u043d\u0435 \u0431\u044b\u043b\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u0441\u0438\u0433\u043d\u0430\u043b\u044c\u043d\u043e-\u0441\u043b\u043e\u0442\u043e\u0432\u044b\u0445 \u0441\u0432\u044f\u0437\u0435\u0439. \u0418 \u0442\u0443\u0442 \u0432\u0441\u043f\u043b\u044b\u043b\u0430 <a href=\"http:\/\/qt-project.org\/doc\/qt-5.1\/qtdoc\/moc.html#limitations\">\u0431\u044f\u043a\u0430<\/a>: \u00abMOC \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0421++. \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e <i>\u0448\u0430\u0431\u043b\u043e\u043d\u044b \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u0441\u0438\u0433\u043d\u0430\u043b\u044b \u0438\u043b\u0438 \u0441\u043b\u043e\u0442\u044b<\/i>\u00bb. #@&#038;*!<br \/>  \u0412\u043f\u0440\u043e\u0447\u0435\u043c, \u0438 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443 \u044f \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0435\u043e\u0434\u043e\u043b\u0435\u043b.<\/p>\n<p>  \u042f \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u044b:  <\/p>\n<ol>\n<li>\u0432\u0430\u0448 \u0440\u043e\u0434\u043d\u043e\u0439 \u043a\u043b\u0430\u0441\u0441 T;<\/li>\n<li>\u0435\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u2014 CreatorBase (\u043f\u043e\u0442\u043e\u043c\u043e\u043a QObject). \u041e\u043d \u0432 \u0441\u043b\u043e\u0442\u0435 \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438 \u0435\u0433\u043e \u0430\u0434\u0440\u0435\u0441 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u043c;<\/li>\n<li>\u0435\u0441\u0442\u044c \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u044f \u2014 Creator&lt;T&gt; (\u043f\u043e\u0442\u043e\u043c\u043e\u043a CreatorBase). \u041e\u043d \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430;<\/li>\n<li>\u0435\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441 ThreadedObjectBase (\u043f\u043e\u0442\u043e\u043c\u043e\u043a QObject), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u043f\u043e\u0442\u043e\u043a. \u041e\u043d \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442-\u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u044c CreatorBase \u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0441\u0438\u0433\u043d\u0430\u043b\u044c\u043d\u043e-\u0441\u043b\u043e\u0442\u043e\u0432\u044b\u0435 \u0441\u0432\u044f\u0437\u0438;<\/li>\n<li>\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0438 \u043f\u043e\u0442\u043e\u043a\u0430 ThreadedObject&lt;T&gt; (\u043f\u043e\u0442\u043e\u043c\u043e\u043a ThreadedObjectBase). \u041e\u043d \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0438 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b * \u0438 -&gt;, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0442\u0438\u043f\u0430 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430;<\/li>\n<li>\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043a\u043b\u0430\u0441\u0441 (\u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u0442\u043e\u043c\u043a\u043e\u043c QObject), \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u043e \u0436\u0435\u043b\u0430\u043d\u0438\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0441\u0438\u0433\u043d\u0430\u043b \u00ab\u043a\u043b\u0430\u0441\u0441 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b \u0440\u0430\u0431\u043e\u0442\u0443\u00bb \u0438 \u0441\u043b\u043e\u0442 \u00ab\u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u044b\u00bb, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u0434\u0430\u0442\u044c <a href=\"http:\/\/qt-project.org\/doc\/qt-5.1\/qtcore\/qobject.html#deleteLater\">\u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0435 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430<\/a>.<\/li>\n<\/ol>\n<p>  \u041f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e\u0439:  <\/p>\n<ol>\n<li>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0438 \u043f\u043e\u0442\u043e\u043a\u0430 ThreadedObject;<\/li>\n<li>\u043e\u043d \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u0430 Creator \u0438 QThread \u0434\u043b\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430;<\/li>\n<li>\u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u0432 \u043d\u043e\u0432\u044b\u0439 \u043f\u043e\u0442\u043e\u043a;<\/li>\n<li>\u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0441\u0438\u0433\u043d\u0430\u043b\u044c\u043d\u043e-\u0441\u043b\u043e\u0442\u043e\u0432\u044b\u0435 \u0441\u0432\u044f\u0437\u0438;<\/li>\n<li>\u0432\u043d\u043e\u0432\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0441 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c;<\/li>\n<li>\u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 T;<\/li>\n<li>ThreadedObjectBase \u0443\u0437\u043d\u0430\u0435\u0442 \u043e\u0431 \u044d\u0442\u043e\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043b\u043e\u0442\u0430 setObject (void *Obj), \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 \u0430\u0434\u0440\u0435\u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0438 \u043e\u043f\u043e\u0432\u0435\u0449\u0430\u0435\u0442 \u043e\u0431 \u044d\u0442\u043e\u043c \u043c\u0438\u0440\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0438\u0433\u043d\u0430\u043b\u0430 objectIsReady ();<\/li>\n<li>\u043e\u0431 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u043c \u0444\u0438\u043d\u0430\u043b\u0435 \u0432\u0441\u0435\u0445 \u044d\u0442\u0438\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u043c\u043e\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u0443 bool ThreadedObject&lt;T&gt;::objectIsCreated (void) const.<\/li>\n<\/ol>\n<h4>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h4>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u043e\u0434 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 (\u0447\u0442\u043e\u0431\u044b \u043e\u043d\u043e \u0432\u0441\u0435 \u0432\u043b\u0435\u0437\u043b\u043e \u0432 \u044d\u043a\u0440\u0430\u043d, \u044f \u0443\u0431\u0440\u0430\u043b \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438).<br \/>  \u0421\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432:<\/p>\n<pre><code class=\"cpp\">class CreatorBase: public QObject { Q_OBJECT \tvoid\t*_obj; protected:\tvirtual void *Allocation (void) = 0; public slots:\tvoid allocate (void)\t\t{ emit setObject (Allocation ()); } signals:\tvoid setObject (void *Obj); };  template &lt;class T&gt; class Creator: public CreatorBase { protected: void *Allocation (void) { return reinterpret_cast &lt;void*&gt; (new T); } };  <\/code><\/pre>\n<p>  \u0422\u0443\u0442 \u0432\u0441\u0435 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e: \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u044f CreatorBase \u0438\u043c\u0435\u0435\u0442 \u0441\u043b\u043e\u0442 allocate (), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0443\u0449\u0435\u043d \u0432 \u043d\u043e\u0432\u043e\u043c \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435. \u041e\u043d \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u0438\u0433\u043d\u0430\u043b setObject (void *Obj), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u0430\u0434\u0440\u0435\u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0432 \u043f\u043e\u0442\u043e\u043c\u043a\u0435 void *Creator&lt;T&gt;::Allocation ().<\/p>\n<p>  \u0411\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 ThreadedObjectBase \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"cpp\">class ThreadedObjectBase: public QObject { \tQ_OBJECT  protected: \tQThread\t*_thread;  \tvirtual void SetObjectPointer (void *Ptr) = 0; \tThreadedObjectBase (QObject *parent = 0): QObject (parent), _thread (0) {}  \tvoid starting (CreatorBase *Creator, QThread::Priority Priority = QThread::InheritPriority, bool ToDeleteLaterThread = true) \t{ \t\tbool res;\t\t\t \t\t_thread = new QThread; \t\tCreator-&gt;moveToThread (_thread); \t\tres = connect (_thread, SIGNAL (started ()), Creator, SLOT (allocate ())); \t\tQ_ASSERT_X (res, &quot;connect&quot;, &quot;connection is not established&quot;); \t\tres = connect (Creator, SIGNAL (setObject (void*)), this, SLOT (setObject (void*))); \t\tQ_ASSERT_X (res, &quot;connect&quot;, &quot;connection is not established&quot;); \t\tif (ToDeleteLaterThread) \t\t{ \t\t\tres = connect (_thread, SIGNAL (finished ()), _thread, SLOT (deleteLater ())); \t\t\tQ_ASSERT_X (res, &quot;connect&quot;, &quot;connection is not established&quot;); \t\t} \t\t_thread-&gt;start (Priority); \t}  public: \tvirtual ~ThreadedObjectBase (void)\t\t{ if (_thread) delete _thread; } \tQThread *thread (void)\t{ return _thread; } \tconst QThread *cthread (void) const\t{ return _thread; }  signals: \tvoid objectIsReady (void);  private slots: \tvoid setObject (void *Obj)\t\t{ SetObjectPointer (Obj); emit objectIsReady (); } }; <\/code><\/pre>\n<p>  \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u0442\u0443\u0442 \u2014 starting. \u041e\u043d \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043f\u043e\u0442\u043e\u043a \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c. \u041f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043f\u043e\u0442\u043e\u043a _thread \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u0438\u0433\u043d\u0430\u043b <a href=\"http:\/\/qt-project.org\/doc\/qt-5.1\/qtcore\/qthread.html#started\">QThread::started ()<\/a>. \u042d\u0442\u043e\u0442 \u0441\u0438\u0433\u043d\u0430\u043b \u043c\u044b \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e \u0441\u043b\u043e\u0442\u043e\u043c CreatorBase::allocate (), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442. \u0422\u043e\u0442, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u0438\u0433\u043d\u0430\u043b CreatorBase::setObject (void *), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043f\u043e\u0434\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0441\u043b\u043e\u0442\u043e\u043c ThreadedObjectBase::setObject (void *Obj). \u0412\u0441\u0435, \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u043e\u0437\u0434\u0430\u043d (\u043e \u0447\u0435\u043c \u0432\u044b\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u0438\u0433\u043d\u0430\u043b ThreadedObjectBase::objectIsReady () ), \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043d\u0435\u0433\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0436\u0435\u043b\u0430\u0435\u0442 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0435 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u043e\u0442\u043e\u043a\u0430 (\u0447\u0442\u043e \u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u043e), \u0442\u043e \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0432\u044f\u0437\u044c \u0432\u043d\u0443\u0442\u0440\u0438 _thread <a href=\"http:\/\/qt-project.org\/doc\/qt-5.1\/qtcore\/qthread.html#finished\">QThread::finished ()<\/a> -&gt; <a href=\"http:\/\/qt-project.org\/doc\/qt-5.1\/qtcore\/qobject.html#deleteLater\">QObject::deleteLater ()<\/a>.<br \/>  \u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0438\u043c\u044f \u0441\u0438\u0433\u043d\u0430\u043b\u0430 (\u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 _finished_signal). \u042d\u0442\u043e\u0442 \u0441\u0438\u0433\u043d\u0430\u043b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c \u043f\u043e \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u0438 \u0441\u0432\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b. \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0441\u043b\u043e\u0442 \u0438\u0437 _terminate_slot \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u043c \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u043e\u0442\u043e\u043a\u0430 (\u043f\u043e\u0442\u043e\u043a, \u0432\u043f\u0440\u043e\u0447\u0435\u043c, \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0435 \u043c\u0433\u043d\u043e\u0432\u0435\u043d\u043d\u043e; \u0434\u043e\u0436\u0434\u0430\u0442\u044c\u0441\u044f \u0435\u0433\u043e \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u043e\u0432\u043e\u043c thread()-&gt;wait \u2014 \u0441\u043c. <a href=\"http:\/\/qt-project.org\/doc\/qt-5.1\/qtcore\/qthread.html#wait\">QThread::wait<\/a>).<\/p>\n<p>  \u041d\u0443 \u0438 \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u0432\u0438\u0434\u0438\u043c\u044b\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441:<\/p>\n<pre><code class=\"cpp\">template &lt;class T&gt; class ThreadedObject: public ThreadedObjectBase { private: \tCreator&lt;T&gt; *_creator;  protected: \tT*\t_obj; \tconst char\t*_finished_signal; \tconst char\t*_terminate_slot; \tbool\t\t_to_delete_later_object;  \tvoid SetObjectPointer (void *Ptr) \t{ \t\tbool res;  \t\t_obj = reinterpret_cast &lt;T*&gt; (Ptr);  \t\tif (_finished_signal) \t\t{ \t\t\tres = connect (_obj, _finished_signal, _thread, SLOT (quit ())); \t\t\tQ_ASSERT_X (res, &quot;connect&quot;, &quot;connection is not established&quot;); \t\t}  \t\tif (_terminate_slot) \t\t{ \t\t\tres = connect (_thread, SIGNAL (finished ()), _obj, _terminate_slot); \t\t\tQ_ASSERT_X (res, &quot;connect&quot;, &quot;connection is not established&quot;); \t\t} \t\t \t\tif (_to_delete_later_object && _finished_signal) \t\t{ \t\t\tres = connect (_obj, _finished_signal, _obj, SLOT (deleteLater ())); \t\t\tQ_ASSERT_X (res, &quot;connect&quot;, &quot;connection is not established&quot;); \t\t} \t}  public: \tThreadedObject (QObject *parent = 0): ThreadedObjectBase (parent), _obj (0), _creator (0) \t\t{ } \t~ThreadedObject  (void)\t{ if (_creator) delete _creator; } \tvoid start (const char *FinishedSignal = 0, const char *TerminateSlot = 0, QThread::Priority Priority = QThread::InheritPriority, bool ToDeleteLaterThread = true, bool ToDeleteLaterObject = true) \t{ \t\t_finished_signal = FinishedSignal; \t\t_terminate_slot = TerminateSlot; \t\t_to_delete_later_object = ToDeleteLaterObject; \t\tstarting (new Creator&lt;T&gt;, Priority, ToDeleteLaterThread); \t}  \tbool objectIsCreated (void) const\t{ return _obj != 0; }  \tT* ptr (void) \t\t\t{ return reinterpret_cast &lt;T*&gt; (_obj); } \tconst T* cptr (void) const\t{ return reinterpret_cast &lt;const T*&gt; (_obj); }  \t\/\/ . \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0438 \toperator T* (void)\t\t\t{ return ptr (); } \tT* operator -&gt; (void)\t\t{ return ptr (); } \toperator const T* (void) const\t{ return cptr (); } \tconst T* operator -&gt; (void) const\t{ return cptr (); }\t }; <\/code><\/pre>\n<p>  \u0422\u0443\u0442 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u2014 start, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 \u0438\u043c\u0435\u043d\u0430 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432 \u0438 \u0441\u043b\u043e\u0442\u043e\u0432, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0435 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430. \u041c\u0435\u0442\u043e\u0434 objectIsCreated () \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0438\u0441\u0442\u0438\u043d\u0443 \u043a\u043e\u0433\u0434\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 \u0443\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u043d. \u041c\u043d\u043e\u0433\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c ThreadedObject&lt;T&gt; \u043a\u0430\u043a \u00ab\u0443\u043c\u043d\u044b\u0439\u00bb \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c.<\/p>\n<p>  \u0412\u043e\u0442 \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432:<\/p>\n<pre><code class=\"cpp\"> ThreadedObject &lt;Operation&gt; _obj; QObject::connect (&_obj, SIGNAL (objectIsReady ()), this, SLOT (connectObject ())); _obj.start (SIGNAL (finished ()), SLOT (terminate ()), QThread::HighPriority);  <\/code><\/pre>\n<p>  \u0421\u043d\u0438\u0437\u0443 \u043f\u0440\u0438\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u2014 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043a\u043d\u043e\u043f\u043a\u0430. \u0412 \u043d\u043e\u0432\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0442\u0438\u043f\u0430 int, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u0438\u0433\u043d\u0430\u043b \u043e\u0442 \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043f\u043e \u0442\u0430\u0439\u043c\u0435\u0440\u0443. \u041e\u0431\u0430 \u044d\u0442\u0438\u0445 \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u044e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 int, \u043f\u043e \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044e \u043d\u0443\u043b\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u043b\u043e\u0442 <a href=\"http:\/\/qt-project.org\/doc\/qt-5.1\/qtcore\/qcoreapplication.html#quit\">QCoreApplication::quit ()<\/a>. \u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u043f\u043e\u0442\u043e\u043a. \u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u043e\u0432\u0435\u0440\u0435\u043d \u0432 WinXP. \u0425\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \u0443\u0441\u043b\u044b\u0448\u0430\u0442\u044c \u043e\u0431 \u0443\u0441\u043f\u0435\u0448\u043d\u044b\u0445 \u0438\u0441\u043f\u044b\u0442\u0430\u043d\u0438\u044f\u0445 \u0432 Linux, MacOS, Android \u0438 <a href=\"http:\/\/qt-project.org\/doc\/qt-5.1\/qtdoc\/supported-platforms.html\">\u043f\u0440\u043e\u0447\u0438\u0445 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430\u0445<\/a>.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0440\u0438\u043c\u0435\u0440 + \u043a\u043b\u0430\u0441\u0441\u044b<\/b><\/p>\n<div class=\"spoiler_text\">\u0424\u0430\u0439\u043b ThreadedObject:<\/p>\n<pre><code class=\"cpp\">\/\/ ** \/\/ **  \u0411\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \/\/ **  class CreatorBase: public QObject { Q_OBJECT \tvoid\t*_obj;\t\t\t\t\t\t\t\t\t\t\/\/ \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 protected:\t\tvirtual void *Allocation (void) = 0;\t\/\/ \u0442\u0443\u0442 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 public slots:\tvoid allocate (void)\t\t{ emit setObject (Allocation ()); }\t\/\/ \u0441\u043b\u043e\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 signals:\t\tvoid setObject (void *Obj);\t\t\t\t\/\/ \u0432\u044b\u0434\u0430\u0447\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 };  \/\/ ** \/\/ **  \u0411\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u043e\u0442\u043e\u043a\u0430 \/\/ **  class ThreadedObjectBase: public QObject { \tQ_OBJECT  protected: \tQThread\t*_thread;\t\t\t\t\/\/ \u043f\u043e\u0442\u043e\u043a  \tvirtual void SetObjectPointer (void *Ptr) = 0;\t\t\/\/ \u0442\u0443\u0442 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 \tThreadedObjectBase (QObject *parent = 0): QObject (parent), _thread (0) {}\t\t\/\/ \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u0435\u0434\u043a\u0430  \tvoid starting (CreatorBase *Creator, QThread::Priority Priority = QThread::InheritPriority, bool ToDeleteLaterThread = true)\t\t\/\/ \u0437\u0430\u043f\u0443\u0441\u043a \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 \t{ \t\tbool res;\t\t\t\t\t\t\t\/\/ \u043f\u0440\u0438\u0437\u043d\u0430\u043a \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0441\u0442\u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432-\u0441\u043b\u043e\u0442\u043e\u0432 \t\t_thread = new QThread;\t\t\/\/ \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u043e\u0442\u043e\u043a\u0430 \t\tCreator-&gt;moveToThread (_thread);\t\t\/\/ \u043f\u0435\u0440\u0435\u043d\u043e\u0441 _creator \u0432 \u043f\u043e\u0442\u043e\u043a \t\tres = connect (_thread, SIGNAL (started ()), Creator, SLOT (allocate ()));\t\t\t\tQ_ASSERT_X (res, &quot;connect&quot;, &quot;connection is not established&quot;);\t\/\/ \u0437\u0430\u043f\u0443\u0441\u043a \u043f\u043e\u0442\u043e\u043a\u0430 _thread \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 Creator-\u043e\u043c \t\tres = connect (Creator, SIGNAL (setObject (void*)), this, SLOT (setObject (void*)));\tQ_ASSERT_X (res, &quot;connect&quot;, &quot;connection is not established&quot;);\t\/\/ Creat-\u043e\u0440 \u0432\u044b\u0434\u0430\u0435\u0442 \u0430\u0434\u0440\u0435\u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \t\tif (ToDeleteLaterThread)\t\t\t\/\/ \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0435 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 thread? \t\t{\tres = connect (_thread, SIGNAL (finished ()), _thread, SLOT (deleteLater ()));\t\tQ_ASSERT_X (res, &quot;connect&quot;, &quot;connection is not established&quot;);\t}\t\/\/ \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u0442\u043e\u043a\u0430 _thread \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0435 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \t\t_thread-&gt;start (Priority);\t\t\t\/\/ \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u0430 \t}  public: \t\/\/ . \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \tvirtual ~ThreadedObjectBase (void)\t\t{ if (_thread) delete _thread; }\t\t\t\/\/ \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u0432 \tQThread *thread (void)\t{ return _thread; }\t\t\t\t\/\/ \u043f\u043e\u0442\u043e\u043a, \u0432\u043b\u0430\u0434\u0435\u044e\u0449\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c  \t\/\/ . \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \tconst QThread *cthread (void) const\t{ return _thread; }\t\t\/\/ \u043f\u043e\u0442\u043e\u043a, \u0432\u043b\u0430\u0434\u0435\u044e\u0449\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c  signals: \tvoid objectIsReady (void);\t\t\t\t\/\/ \u0441\u0438\u0433\u043d\u0430\u043b &quot;\u043e\u0431\u044a\u0435\u043a\u0442 \u0433\u043e\u0442\u043e\u0432&quot;  private slots: \tvoid setObject (void *Obj)\t\t\t\t{ SetObjectPointer (Obj); emit objectIsReady (); }\t\t\/\/ \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0430\u0434\u0440\u0435\u0441\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 };\t\/\/ class ThreadedObjectBase  \/\/ ** \/\/ **  \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u043e\u0442\u043e\u043a\u0430 \/\/ **  template &lt;class T&gt; class ThreadedObject: public ThreadedObjectBase { private: \ttemplate &lt;class T&gt; class Creator: public CreatorBase\t\t\/\/ \u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432 \u043f\u043e\u0442\u043e\u043a\u0435 \t{ protected: void *Allocation (void) { return reinterpret_cast &lt;void*&gt; (new T); } }; \tCreator&lt;T&gt; *_creator;\t\t\/\/ \u043a\u043b\u0430\u0441\u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432 \u043f\u043e\u0442\u043e\u043a\u0435  protected: \tT*\t_obj;\t\t\t\t\t\t\/\/ \u043e\u0431\u044a\u0435\u043a\u0442 \tconst char\t*_finished_signal;\t\t\t\/\/ \u0441\u0438\u0433\u043d\u0430\u043b &quot;\u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u0430&quot; \tconst char\t*_terminate_slot;\t\t\t\/\/ \u0441\u043b\u043e\u0442 &quot;\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0440\u0430\u0431\u043e\u0442\u044b&quot; \tbool\t\t_to_delete_later_object;\t\/\/ \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c &quot;\u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u0435 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430?  \tvoid SetObjectPointer (void *Ptr)\t\t\/\/ \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0441\u0432\u044f\u0437\u0435\u0439 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \t{ \t\tbool res;\t\t\t\t\t\t\t\/\/ \u043f\u0440\u0438\u0437\u043d\u0430\u043a \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0441\u0442\u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432-\u0441\u043b\u043e\u0442\u043e\u0432  \t\t_obj = reinterpret_cast &lt;T*&gt; (Ptr);\t\/\/ \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442  \t\tif (_finished_signal)\t\t\t\t\/\/ \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u0438\u0433\u043d\u0430\u043b &quot;\u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u0430&quot;? \t\t{\tres = connect (_obj, _finished_signal, _thread, SLOT (quit ()));\t\t\tQ_ASSERT_X (res, &quot;connect&quot;, &quot;connection is not established&quot;);\t}\t\/\/ \u043f\u043e \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044e \u0440\u0430\u0431\u043e\u0442\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043f\u043e\u0442\u043e\u043a \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d \t\tif (_terminate_slot)\t\t\t\t\/\/ \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u043b\u043e\u0442 &quot;\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0440\u0430\u0431\u043e\u0442\u044b&quot;? \t\t{\tres = connect (_thread, SIGNAL (finished ()), _obj, _terminate_slot);\tQ_ASSERT_X (res, &quot;connect&quot;, &quot;connection is not established&quot;);\t}\t\/\/ \u043f\u0435\u0440\u0435\u0434 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u043e\u0439 \u043f\u043e\u0442\u043e\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d \u0441\u043b\u043e\u0442 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 &quot;\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0440\u0430\u0431\u043e\u0442\u044b&quot; \t\tif (_to_delete_later_object && _finished_signal)\t\/\/ \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0435 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430? \t\t{\tres = connect (_obj, _finished_signal, _obj, SLOT (deleteLater ()));\tQ_ASSERT_X (res, &quot;connect&quot;, &quot;connection is not established&quot;);\t}\t\/\/ \u043f\u043e \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044e \u0440\u0430\u0431\u043e\u0442\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0431\u0443\u0434\u0435\u0442 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043e \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0435 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \t}  public: \t\/\/ . \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \tThreadedObject (QObject *parent = 0): ThreadedObjectBase (parent), _obj (0), _creator (0) {}\t\/\/ \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \t~ThreadedObject  (void)\t{ if (_creator) delete _creator; }\t\t\/\/ \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \tvoid start (const char *FinishedSignal = 0, const char *TerminateSlot = 0, QThread::Priority Priority = QThread::InheritPriority, bool ToDeleteLaterThread = true, bool ToDeleteLaterObject = true)\t\t\/\/ \u0437\u0430\u043f\u0443\u0441\u043a \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 \t{ \t\t_finished_signal = FinishedSignal;\t\t\/\/ \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u043d\u0438\u0435 \u0438\u043c\u0435\u043d\u0438 \u0441\u0438\u0433\u043d\u0430\u043b\u0430 &quot;\u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u0430&quot; \t\t_terminate_slot = TerminateSlot;\t\t\/\/ \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u043d\u0438\u0435 \u0438\u043c\u0435\u043d\u0438 \u0441\u043b\u043e\u0442\u0430 &quot;\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0440\u0430\u0431\u043e\u0442\u044b&quot; \t\t_to_delete_later_object = ToDeleteLaterObject;\t\/\/ \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u043d\u0438\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \t\tstarting (new Creator&lt;T&gt;, Priority, ToDeleteLaterThread);\t\/\/ \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \t}  \t\/\/ . \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \tbool objectIsCreated (void) const\t{ return _obj != 0; }\t\t\t\t\t\t\t\/\/ \u043e\u0431\u044a\u0435\u043a\u0442 \u0433\u043e\u0442\u043e\u0432 \u043a \u0440\u0430\u0431\u043e\u0442\u0435?  \tT* ptr (void) \t\t\t\t{ return reinterpret_cast &lt;T*&gt; (_obj); }\t\t\t\/\/ \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 \tconst T* cptr (void) const\t{ return reinterpret_cast &lt;const T*&gt; (_obj); }\t\t\/\/ \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442  \t\/\/ . \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0438 \toperator T* (void)\t\t\t\t\t{ return ptr (); }\t\t\/\/ \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 \tT* operator -&gt; (void)\t\t\t\t{ return ptr (); }\t\t\/\/ \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 \toperator const T* (void) const\t\t{ return cptr (); }\t\t\/\/ \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \tconst T* operator -&gt; (void) const\t{ return cptr (); }\t\t\/\/ \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 };\t\/\/ class ThreadedObject  <\/code><\/pre>\n<p>  \u0424\u0430\u0439\u043b main.cpp:<\/p>\n<pre><code class=\"cpp\"> #include &lt;QtGui&gt; #include &lt;QtWidgets&gt; #include &lt;QtCore&gt;   #include &quot;ThreadedObject.h&quot;  \/\/ ** \/\/ **  \u0412\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \/\/ **  class Operation: public QObject { \tQ_OBJECT  \tint\t\t*Int;\t\t\/\/ \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \tQTimer\t_tmr;\t\t\/\/ \u0442\u0430\u0439\u043c\u0435\u0440 \tint\t\t_int_timer;\t\/\/ \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u0442\u0430\u0439\u043c\u0435\u0440  public: \tOperation (void)\t{ Int = new int (5); }\t\t\t\/\/ \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \t~Operation (void)\t{ if (Int) delete Int; }\t\t\/\/ \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440  signals:     void addText(const QString &txt);\t\t\/\/ \u0441\u0438\u0433\u043d\u0430\u043b &quot;\u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0430&quot; \tvoid finished ();\t\t\t\t\t\t\/\/ \u0441\u0438\u0433\u043d\u0430\u043b &quot;\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0440\u0430\u0431\u043e\u0442\u044b&quot;  public slots: \tvoid terminate ()\t\t\t\/\/ \u0434\u043e\u0441\u0440\u043e\u0447\u043d\u0430\u044f \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \t{ \t\tkillTimer (_int_timer);\t\t\/\/ \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0433\u043e \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \t\t_tmr.stop ();\t\t\t\t\/\/ \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0432\u043d\u0435\u0448\u0435\u043d\u0433\u043e \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \t\tdelete Int;\t\t\t\t\t\/\/ \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \t\tInt = 0;\t\t\t\t\t\/\/ \u043f\u0440\u0438\u0437\u043d\u0430\u043a \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b \t\temit finished ();\t\t\t\/\/ \u0441\u0438\u0433\u043d\u0430\u043b \u0437\u0430\u0432\u0435\u0440\u0433\u0435\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b \t}     void doAction (void)\t\t\/\/ \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435     { \t\tbool res; \t\temit addText (QString (&quot;- %1 -&quot;). arg (*Int)); \t\tres = QObject::connect (&_tmr, &QTimer::timeout, this, &Operation::timeout);\tQ_ASSERT_X (res, &quot;connect&quot;, &quot;connection is not established&quot;);\t\/\/ \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u043d\u0438\u0435 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \t\t_tmr.start (2000);\t\t\t\/\/ \u0437\u0430\u043f\u0443\u0441\u043a \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \t\tthread()-&gt;sleep (1);\t\t\/\/ \u0432\u044b\u0436\u0438\u0434\u0430\u043d\u0438\u0435 1 \u0441\u0435\u043a... \t\ttimeout ();\t\t\t\t\t\/\/ ... \u0432\u044b\u0434\u0430\u0447\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f ... \t\tstartTimer (2000);\t\t\t\/\/ ... \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0433\u043e \u0442\u0430\u0439\u043c\u0435\u0440\u0430     } protected: \tvoid timerEvent (QTimerEvent *ev)\t{ timeout (); }\t\t\/\/ \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u0442\u0430\u0439\u043c\u0435\u0440  private slots: \tvoid timeout (void) \t{ \t\tif (!Int || !*Int)\t\t\t\t\t\t\t\t\t\/\/ \u043f\u043e\u0442\u043e\u043a \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f? \t\t\treturn;\t\t\t\t\t\t\t\t\t\t\t\/\/ ... \u0432\u044b\u0445\u043e\u0434 \t\t--*Int;\t\t\t\t\t\t\t\t\t\t\t\t\/\/ \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u0435 \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430 \t\temit addText (QString (&quot;- %1 -&quot;). arg (*Int));\t\t\/\/ \u0432\u044b\u0434\u0430\u0447\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f  \t\tif (!Int || !*Int)\t\t\t\t\t\t\t\t\t\/\/ \u0442\u0430\u0439\u043c\u0435\u0440 \u0437\u0430\u043a\u0440\u044b\u0442? \t\t\temit finished ();\t\t\t\t\t\t\t\t\/\/ ... \u0432\u044b\u0445\u043e\u0434  \t}  };  \/\/ ** \/\/ **  \u041e\u0431\u044a\u0435\u043a\u0442, \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0441 \u043f\u043e\u0442\u043e\u043a\u043e\u043c \/\/ **  class App: public QObject { \tQ_OBJECT  \tThreadedObject &lt;Operation&gt;\t_obj;\t\t\/\/ \u043e\u0431\u044a\u0435\u043a\u0442-\u043f\u043e\u0442\u043e\u043a \tQPushButton _btn;\t\t\t\t\t\t\/\/ \u043a\u043d\u043e\u043f\u043a\u0430  protected: \tvoid timerEvent (QTimerEvent *ev) \t{ \t\tbool res;\t\t\t\t\t\t\t\/\/ \u043f\u0440\u0438\u0437\u043d\u0430\u043a \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0441\u0442\u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432-\u0441\u043b\u043e\u0442\u043e\u0432 \t\tkillTimer (ev-&gt;timerId ());\t\t\t\/\/ \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \t\tres = QObject::connect (&_obj, SIGNAL (objectIsReady ()), this, SLOT (connectObject ()));\t\tQ_ASSERT_X (res, &quot;connect&quot;, &quot;connection is not established&quot;);\t\/\/ \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0441\u0432\u044f\u0437\u0435\u0439 \u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c \t\t_obj.start (SIGNAL (finished ()), SLOT (terminate ()), QThread::HighPriority);\t\t\t\t\t\/\/ \u0437\u0430\u043f\u0443\u0441\u043a \u043f\u043e\u0442\u043e\u043a\u0430 \u0441 \u0432\u044b\u0441\u043e\u043a\u0438\u043c \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043e\u043c \t}  private slots: \tvoid setText (const QString &txt)\t\t{ _btn.setText (txt); }\t\t\/\/ \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043d\u0430\u0434\u043f\u0438\u0441\u0438 \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0435 \tvoid connectObject (void)\t\t\/\/ \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0441\u0432\u044f\u0437\u0435\u0439 \u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c \t{ \t\tbool res;\t\t\t\t\t\/\/ \u043f\u0440\u0438\u0437\u043d\u0430\u043a \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0441\u0442\u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432-\u0441\u043b\u043e\u0442\u043e\u0432 \t\tres = QObject::connect (this, &App::finish, _obj, &Operation::terminate);\t\t\t\tQ_ASSERT_X (res, &quot;connect&quot;, &quot;connection is not established&quot;);\t\/\/ \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0445\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u043f\u043e\u0442\u043e\u043a\u0435 \t\tres = QObject::connect (this, &App::startAction, _obj, &Operation::doAction);\t\t\tQ_ASSERT_X (res, &quot;connect&quot;, &quot;connection is not established&quot;);\t\/\/ \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0441\u0438\u0433\u043d\u0430\u043b\u0430 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \t\tres = QObject::connect (_obj, &Operation::finished, this, &App::finish);\t\t\t\tQ_ASSERT_X (res, &quot;connect&quot;, &quot;connection is not established&quot;);\t\/\/ \u043a\u043e\u043d\u0435\u0446 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \t\tres = QObject::connect (_obj, &Operation::addText, this, &App::setText);\t\t\t\tQ_ASSERT_X (res, &quot;connect&quot;, &quot;connection is not established&quot;);\t\/\/ \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043d\u0430\u0434\u043f\u0438\u0441\u0438 \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 \t\tres = QObject::connect (&_btn, &QPushButton::clicked, _obj, &Operation::terminate);\t\tQ_ASSERT_X (res, &quot;connect&quot;, &quot;connection is not established&quot;);\t\/\/ \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u043e\u0442\u043e\u043a\u0430  \t\t_btn.show ();\t\t\t\t\/\/ \u0432\u044b\u0432\u043e\u0434 \u043a\u043d\u043e\u043f\u043a\u0438 \t\temit startAction ();\t\t\/\/ \u0437\u0430\u043f\u0443\u0441\u043a \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \t}  public slots: \tvoid terminate (void)\t\t\t{ emit finish (); }\t\t\/\/ \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f  signals: \tvoid startAction (void);\t\t\/\/ \u0441\u0438\u0433\u043d\u0430\u043b &quot;\u0437\u0430\u043f\u0443\u0441\u043a \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f&quot; \tvoid finish (void);\t\t\t\t\/\/ \u0441\u0438\u0433\u043d\u0430\u043b &quot;\u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u044b&quot; };  \/\/ ** \/\/ **  \u0422\u043e\u0447\u043a\u0430 \u0432\u0445\u043e\u0434\u0430 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \/\/ **   int main (int argc, char **argv) {     QApplication app (argc, argv);\t\t\/\/ \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \tApp a;\t\t\t\t\t\t\t\t\/\/ \u043e\u0431\u044a\u0435\u043a\u0442 \tbool res;\t\t\t\t\t\t\t\/\/ \u043f\u0440\u0438\u0437\u043d\u0430\u043a \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0441\u0442\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438  \ta.startTimer (0);\t\t\t\t\t\/\/ \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043f\u0440\u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u0446\u0438\u043a\u043b\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \tres = QObject::connect (&a, SIGNAL (finish ()), &app, SLOT (quit ()));\t\t\t\tQ_ASSERT_X (res, &quot;connect&quot;, &quot;connection is not established&quot;);\t\/\/ \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \tres = QObject::connect (&app, SIGNAL (lastWindowClosed ()), &a, SLOT (terminate ()));\tQ_ASSERT_X (res, &quot;connect&quot;, &quot;connection is not established&quot;);\t\/\/ \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442  \treturn app.exec();\t\t\t\t\t\/\/ \u0437\u0430\u043f\u0443\u0441\u043a \u0446\u0438\u043a\u043b\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 }  #include &quot;main.moc&quot;  <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/202312\/\"> http:\/\/habrahabr.ru\/post\/202312\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u0412\u0441\u0435\u043c \u0445\u0430\u0431\u0440\u0430\u043f\u0440\u0438\u0432\u0435\u0442!<br \/>  \u041a\u0430\u043a-\u0442\u043e \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u043b\u043e\u0441\u044c \u043c\u043d\u0435 \u0432 Qt 5.1.1 \u0434\u043b\u044f WinXP \u0432 VS2009 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441 \u0438\u043d\u0442\u0435\u043d\u0441\u0438\u0432\u043d\u044b\u043c \u043e\u0431\u043c\u0435\u043d\u043e\u043c \u0441\u0438\u0433\u043d\u0430\u043b\u0430\u043c\u0438. \u0412\u0437\u044f\u043b \u044f <a href=\"http:\/\/www.labirint.ru\/books\/272473\/\">\u0428\u043b\u0435\u0435<\/a>, \u0432\u044b\u0447\u0438\u0442\u0430\u043b \u0443 \u043d\u0435\u0433\u043e, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u043e\u0442 QThread \u0438 \u2014 \u0432\u0443\u0430\u043b\u044f, \u0432\u0435\u043b\u043a\u043e\u043c \u0432 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c! \u041d\u0430 \u0432\u0441\u044f\u043a\u0438\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 \u0437\u0430\u0433\u043b\u044f\u043d\u0443\u043b \u0432 <a href=\"http:\/\/qt-project.org\/doc\/qt-5.1\/qtcore\/qthread.html#details\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e Qt<\/a> \u2014 \u0442\u0430\u043c \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u0432\u043e\u0437\u0440\u0430\u0436\u0430\u043b \u043f\u0440\u043e\u0442\u0438\u0432 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0442 QThread \u0441\u0432\u043e\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430. \u041d\u0443 \u0447\u0442\u043e \u0436\u0435 \u2014 \u043f\u043e\u0440\u044f\u0434\u043e\u043a, \u0441\u0434\u0435\u043b\u0430\u043d\u043e! \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u044e \u2014 \u0432\u0440\u043e\u0434\u0435 \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u043e \u043a\u0430\u043a-\u0442\u043e \u043d\u0435 \u0442\u0430\u043a\u2026 \u041d\u0430\u0447\u0438\u043d\u0430\u044e \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u043e\u0442\u043b\u0430\u0434\u043a\u0438 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u2014 \u0430 \u0442\u0430\u043c \u0442\u0432\u043e\u0440\u0438\u0442\u0441\u044f \u0447\u0435\u0440\u0442 \u0437\u043d\u0430\u0435\u0442 \u0447\u0442\u043e! \u0422\u043e \u0441\u0438\u0433\u043d\u0430\u043b\u044b \u043d\u0435 \u0432\u044b\u0445\u043e\u0434\u044f\u0442, \u0442\u043e \u0432\u044b\u0445\u043e\u0434\u044f\u0442, \u043d\u043e \u043a\u0430\u043a-\u0442\u043e \u043a\u0440\u0438\u0432\u043e \u0438 \u0438\u0437 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430. \u041e\u0434\u043d\u0438\u043c \u0441\u043b\u043e\u0432\u043e\u043c, \u043f\u043e\u043b\u043d\u044b\u0439 \u0431\u0430\u0440\u0434\u0430\u043a! \u041f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043e\u0441\u043d\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e-google-\u0438\u0442\u044c \u0438 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u0442\u0435\u043c\u0435 (\u043c\u043d\u0435 \u043f\u043e\u043c\u043e\u0433\u043b\u0438 \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/vasinnet.blogspot.com\/2012\/08\/recommended-way-to-using-qthread.html\">\u0442\u0443\u0442<\/a>, <a href=\"http:\/\/habrahabr.ru\/post\/150274\/\">\u0437\u0434\u0435\u0441\u044c<\/a> \u0438 <a href=\"http:\/\/qt-project.org\/wiki\/Threads_Events_QObjects\">\u0442\u0430\u043c<\/a>). \u0412 \u0438\u0442\u043e\u0433\u0435 \u044f \u0441\u0434\u0435\u043b\u0430\u043b \u0448\u0430\u0431\u043b\u043e\u043d \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0430 \u0421++ (\u0432\u0435\u0440\u043d\u0435\u0435, \u0446\u0435\u043b\u0443\u044e \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044e \u043e\u043d\u044b\u0445), \u0447\u0442\u043e \u043c\u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b\u043e \u0432 \u0438\u0442\u043e\u0433\u0435 \u043f\u0438\u0441\u0430\u0442\u044c (\u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e) \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043a\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430, \u0436\u0438\u0432\u0443\u0449\u0435\u0433\u043e \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0438 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-202312","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/202312","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=202312"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/202312\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=202312"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=202312"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=202312"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}