Results 1 to 2 of 2

Thread: simple thread layout question

  1. #1
    Join Date
    Jan 2006
    Location
    Maui, Hawaii
    Posts
    120
    Thanks
    65
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default simple thread layout question

    Hi,

    The lemonade factory where I work has a Qt application that has two command clients to activate lemonade mixing devices with embedded motor command servers.

    For some reason the custom class I use to connect to these command servers takes a LONG time. So I decided to do the connecting in a different thread.

    In my main app I have code like this:
    Qt Code:
    1. commandClient = NULL;
    2. command_thread.cmd = commandClient;
    3. command_thread.start();
    To copy to clipboard, switch view to plain text mode 

    Then the thread instantiates the command client (the connection happens in the constructor). When it finishes, it emits a connection_finished() signal.

    When my app gets this signal it sets it's own pointer to the command client to the one used by the thread:
    Qt Code:
    1. commandClient = command_thread.commandClient;
    To copy to clipboard, switch view to plain text mode 
    Then it does the necessary connections on the thread.

    My question:

    Is this a legitimate way of doing threading? It seems to run great. I only do this task once in the background, but my understanding says things can get hairy if different threads exchange objects.

    When I quit the GUI I try to delete the commandClient and I get this error:
    ASSERT failure in QCoreApplication::sendEvent: "Cannot send events to objects owned by a different thread. Current thread 80f9130. Receiver '' (of type 'LemonadeCmdClient') was created in thread 80f35e8", file kernel/qcoreapplication.cpp, line 289
    Then it seg faults. Any ideas?

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

    Default Re: simple thread layout question

    Make the connection (or better yet, the whole client object) in the run() method of the thread or use QObject::moveToThread to move the client object to the worker thread. Alternatively enforce queued connections.

  3. The following user says thank you to wysota for this useful post:

    mhoover (14th August 2006)

Similar Threads

  1. QTextEdit simple question
    By Marcopolo in forum Qt Tools
    Replies: 4
    Last Post: 11th October 2007, 00:01
  2. Simple Question on Variable initialization
    By Naveen in forum Qt Programming
    Replies: 3
    Last Post: 17th March 2006, 11:01
  3. a simple question: spinbox
    By mickey in forum Newbie
    Replies: 3
    Last Post: 27th February 2006, 15:37
  4. simple question on Class-Members
    By mickey in forum General Programming
    Replies: 7
    Last Post: 4th February 2006, 22:37
  5. QTextEdit Qt4: simple question
    By TheKedge in forum Qt Programming
    Replies: 4
    Last Post: 18th January 2006, 12:03

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.