{"id":21022396,"url":"https://github.com/andreicherniaev/qthread-with-movetothread_qtimer","last_synced_at":"2026-04-17T08:03:26.734Z","repository":{"id":262758145,"uuid":"888262016","full_name":"AndreiCherniaev/QThread-with-moveToThread_QTimer","owner":"AndreiCherniaev","description":"how make multi-thread proj with QTimer","archived":false,"fork":false,"pushed_at":"2025-02-10T12:31:55.000Z","size":19,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-13T18:12:30.544Z","etag":null,"topics":["example","qt"],"latest_commit_sha":null,"homepage":"https://forum.qt.io/topic/159713/killtimer-timers-cannot-be-stopped-from-another-thread","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AndreiCherniaev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-14T04:57:39.000Z","updated_at":"2025-02-09T14:28:56.000Z","dependencies_parsed_at":"2024-11-14T05:27:52.710Z","dependency_job_id":"343029eb-9712-4bf2-885b-b1e4dea24b33","html_url":"https://github.com/AndreiCherniaev/QThread-with-moveToThread_QTimer","commit_stats":null,"previous_names":["andreicherniaev/qthread-with-movetothread_qtimer"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/AndreiCherniaev/QThread-with-moveToThread_QTimer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndreiCherniaev%2FQThread-with-moveToThread_QTimer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndreiCherniaev%2FQThread-with-moveToThread_QTimer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndreiCherniaev%2FQThread-with-moveToThread_QTimer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndreiCherniaev%2FQThread-with-moveToThread_QTimer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AndreiCherniaev","download_url":"https://codeload.github.com/AndreiCherniaev/QThread-with-moveToThread_QTimer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndreiCherniaev%2FQThread-with-moveToThread_QTimer/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269916215,"owners_count":24495860,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-11T02:00:10.019Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["example","qt"],"created_at":"2024-11-19T11:11:37.827Z","updated_at":"2026-04-17T08:03:26.691Z","avatar_url":"https://github.com/AndreiCherniaev.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"## About\nQt example how make multi-thread app with QTimer.\n## Compiling\n```\ngit clone https://github.com/AndreiCherniaev/QThread-with-moveToThread_QTimer.git \u0026\u0026 cd QThread-with-moveToThread_QTimer\nmkdir build/\ncmake -S src/ -B build/ --fresh # qt-cmake -S src/ -B build/ -DCMAKE_BUILD_TYPE=Release --fresh\ncmake --build build/ --parallel\n```\n## Run\nTested on Ubuntu 24.04.1 LTS, Qt 6.8.0 with Debug and Release profiles. If push \"Stop running program.\" in Qt Creator there is no problem, so please run proj in terminal. Start proj and push Ctrl+C to exit...\n```\n$ build/QThread_QTimer\n\nWorker::Worker\nMainWindow::MainWindow\nthread-\u003estart()\nparents QObject(0x0) MainClass(0x7fffc35c40e0)\nWorker::run\nthread;askTim;0x7b6260960000\nthread;GetTime;0x7b625ca006c0;0\n^CWelcome to Signal handled:  2\nrequestInterruption\nemit finished()\nthreadIsFinished\n~MainWindow()\n~Worker()\nQObject::killTimer: Timers cannot be stopped from another thread\nQObject::~QObject: Timers cannot be stopped from another thread\n```\n## Problem\n1) Looks like problem reason is `emit GetTimeAsk()` but this signal is connected to slot using `Qt::QueuedConnection` [connection type](https://doc.qt.io/qt-6/threads-qobject.html#signals-and-slots-across-threads):\n\"Queued Connection The slot is invoked when control returns to the event loop of the receiver's thread. The slot is executed in the receiver's thread\"\n```\nconnect(this, \u0026MainClass::GetTimeAsk, worker.get(), \u0026Worker::GetTime, Qt::QueuedConnection);\n```\n2) And threads is really different: `emit GetTimeAsk()` located in thread 0x7b6260960000 and slot `GetTime()` is started from 0x7b625ca006c0 thread... Sounds like problem should not be but in log we have\n```\nQObject::killTimer: Timers cannot be stopped from another thread\nQObject::~QObject: Timers cannot be stopped from another thread\n```\n3) Insted of `Qt::QueuedConnection` I have tried `Qt::AutoConnection`, but problem still the same.  \n4) Another idea was that `tim= new QTimer(this)` is started in incorrect thread but I don't think so because in log I see first `thread-\u003estart()` and then `Worker::run`.  \n5) Anothere idead is to use QScopedPointer: `QScopedPointer\u003cQTimer\u003e tim` instead of `QTimer *tim`, but problem is the same.  \n\n## How to fix\nInstead of `QScopedPointer\u003cWorker\u003e worker` use raw pointer `Worker *worker`, see [raw_pointer](https://github.com/AndreiCherniaev/QThread-with-moveToThread_QTimer/tree/raw_pointer) branch.\n\n## See also\n\u003cp align=\"center\"\u003e\n  \u003cimg alt=\"image from article Правильная работа с потоками в Qt\" src=\"https://habrastorage.org/webt/zs/py/t2/zspyt2yti1t8-mr6k708rer0rao.png\" width=\"800\"\u003e\n  \u003cbr\u003e\n    \u003cem\u003eQt hierarchy\u003c/em\u003e\n\u003c/p\u003e\n\nRead official [doc](https://doc.qt.io/qt-6/threads-qobject.html) and check official [example](https://doc.qt.io/qt-6/qthread.html). See [article](https://www.toptal.com/qt/qt-multithreading-c-plus-plus).\nAbout SigInt (Ctrl+C) quit see [example](https://github.com/AndreiCherniaev/QCoreApplication_quit_example).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreicherniaev%2Fqthread-with-movetothread_qtimer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandreicherniaev%2Fqthread-with-movetothread_qtimer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreicherniaev%2Fqthread-with-movetothread_qtimer/lists"}