Converting QDialog objects to void/Threading with Qt
-
I first tried the usual threading solutions using std::thread and CreateThread, but I ran into the same issue twice with them. I can not cast in any form I've tried my QDialog class to void or LPTHREADSTARTROUTINE to be used.
What I am trying to do:
void mydialog::function() { qDebug("Thread"); Sleep(5000); } void mydialog::on_go_clicked() { startinnewthread(function); }
When I try to just call function() the Sleep() freezes my UI (As Expected), but my usual way around this is to run it in a new thread so the UI doesn't freeze, but I can't figure out how to do this with Qt.
I tried QThreads, but the multiple things I tried did not work and seemed a bit confusing and not able to simply run a function in a separate thread. -
If you want a function to be run in a seperate thread you should use QtConcurrent: http://doc.qt.io/qt-5/qtconcurrentrun.html#running-a-function-in-a-separate-thread
QtConcurrent::run(this, &mydialog::function, optional_arg);