Results 1 to 8 of 8

Thread: Qt Threading

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Qt Threading

    Exactly. But you can easily work it around by creating another object which lives in the correct thread and move those slots there:
    Qt Code:
    1. class ReconstructionObject : public QObject {
    2. ...
    3. public slots:
    4. void startMethod(int iToStart);
    5. void stopMethod(int iToStop);
    6.  
    7. signals:
    8. void methodFinished();
    9. };
    To copy to clipboard, switch view to plain text mode 
    Then you have two options: 1) create ReconstructionObject in ReconstructionThread::run():
    Qt Code:
    1. void ReconstructionThread::run()
    2. {
    3. ReconstructionObject object;
    4. // connect signals and slots
    5. exec();
    6. }
    To copy to clipboard, switch view to plain text mode 
    or 2) create it somewhere outside and use QObject::moveToThread():
    Qt Code:
    1. ReconstructionThread* thread = new ReconstructionThread(parent);
    2. ReconstructionObject* object = new ReconstructionObject;
    3. object->moveToThread(thread);
    4. thread->start();
    5.  
    6. // and for example something like this to handle cleanup
    7. connect(object, SIGNAL(methodFinished()), object, SLOT(deleteLater()));
    8. connect(object, SIGNAL(destroyed()), thread , SLOT(quit()));
    9. connect(thread, SIGNAL(finished()), thread , SLOT(deleteLater()));
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  2. The following user says thank you to jpn for this useful post:

    avh (30th May 2008)

Similar Threads

  1. Correct Threading Technique
    By themusicalguy in forum Qt Programming
    Replies: 10
    Last Post: 2nd November 2007, 14:28
  2. Threading Issue
    By noufalk in forum Qt Programming
    Replies: 4
    Last Post: 4th August 2007, 13:45
  3. Multi threading ...
    By kiranraj in forum Qt Programming
    Replies: 2
    Last Post: 18th June 2007, 16:51
  4. Threading and plotting graph in same program.
    By sar_van81 in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 9th May 2007, 20:42
  5. Newbie threading question
    By deepayan in forum Qt Programming
    Replies: 17
    Last Post: 16th April 2007, 00:25

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
  •  
Qt is a trademark of The Qt Company.