Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Converting QDialog objects to void/Threading with Qt
Forum Updated to NodeBB v4.3 + New Features

Converting QDialog objects to void/Threading with Qt

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 442 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Contempt
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      bludger
      wrote on last edited by
      #2

      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);
      
      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved