Results 1 to 3 of 3

Thread: Passing parameters to run() or start() method in Qthread class

  1. #1
    Join Date
    Mar 2007
    Posts
    29
    Thanks
    2

    Default Passing parameters to run() or start() method in Qthread class

    Hi,
    I need to pass parameters to the run() method of a Qthread class.
    Actually I set this parameters by a class method that inizialize members in the class but i need to pass them directly to run() or start() method.

    Is this possible?

    Thanks,
    Michele

  2. #2
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Passing parameters to run() or start() method in Qthread class

    Well, you can't pass any parameters to the start method (except priority),
    but you can use an intermediate function (something like start_with_params),
    that can receive them, set your members, and finally run the thread.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Passing parameters to run() or start() method in Qthread class

    How about simply:
    Qt Code:
    1. class MyThread : public QThread {
    2. public:
    3. MyThread(...){
    4. m_arg = -1;
    5. }
    6. void setArg(int a){ m_arg = a; }
    7. protected:
    8. void run(){
    9. doSomething(m_arg);
    10. }
    11. private:
    12. int m_arg;
    13. };
    To copy to clipboard, switch view to plain text mode 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.