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. QThread:create syntax
QtWS25 Last Chance

QThread:create syntax

Scheduled Pinned Locked Moved Solved General and Desktop
qthread
3 Posts 2 Posters 3.5k 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.
  • S Offline
    S Offline
    Sailor Rick
    wrote on 5 Dec 2018, 16:35 last edited by Sailor Rick 12 May 2018, 16:37
    #1

    I am trying the new QThread::create introduced in 5.10 for the first time, but I think I have syntax issues. I want to run a threaded function called "process" in my worker class and pass two arguments with it but it can not link to the public slot in the worker thread as it is not yet defined; I am using Creator 4.7.2 and QT 5.11.2

    QThread *thread = QThread::create(process(data,list));  // has no reference to validate that "process" exists
        parameters_workerThread* worker = new parameters_workerThread();
        worker->moveToThread(thread);
    

    So I re-arranged my code and added the reference to the worker class but gave me an invalid use of void.

    parameters_workerThread* worker = new parameters_workerThread();  // invalid use of void
        QThread *thread = QThread::create(worker->process(data,list));
        worker->moveToThread(thread);
    

    My worker header file looks like this:

    class parameters_workerThread : public QObject
    {
        Q_OBJECT
    public:
        
        parameters_workerThread();
        ~parameters_workerThread();
    
    public slots:
        void process(QByteArray list, QStringList data);
    

    I am compiling with: MingW32- gcc version 5.1.0 (tdm64-1)
    Any direction would be most appreciated

    1 Reply Last reply
    0
    • V Offline
      V Offline
      VRonin
      wrote on 5 Dec 2018, 16:51 last edited by
      #2

      The answer is std::bind

      parameters_workerThread* worker = new parameters_workerThread();
      QThread *thread = QThread::create(std::bind(&parameters_workerThread::process,worker,data,list));
      worker->moveToThread(thread);
      thread->setParent(this);
      thread->start();
      

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      6
      • S Offline
        S Offline
        Sailor Rick
        wrote on 5 Dec 2018, 21:42 last edited by
        #3

        Perfect !!!! What a group !!! Thanks very much, this save me a lot work !!!

        This is an awesome new feature and now I can use it.

        Rick

        1 Reply Last reply
        0

        1/3

        5 Dec 2018, 16:35

        • Login

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