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. How to call functor with QThread

How to call functor with QThread

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 333 Views 1 Watching
  • 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.
  • S Offline
    S Offline
    SRaD
    wrote on last edited by SRaD
    #1

    I have a class with an operator() overloaded.

    class MyWorker : public QObject
    {
        Q_OBJECT
        private:
        // ...
        signals:
            void t_changed(const QString &);
        public:
        void operator()();
            // ...
    };
    

    How does one call the functor of MyWorker using QThread?

    my_worker = std::make_unique<MyWorker>(this);
    // ...
    
    QThread *my_thread = new QThread;
    my_worker->moveToThread(my_thread);
    my_thread->start(); // I want MyWorker::operater()() to be called.
    

    Any help much appreciated.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      If you want to use QThread, you should rather use the working object approach as described in QThread's documentation. Replace that operator with a slot as shown in said documentation.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      4

      • Login

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