Results 1 to 3 of 3

Thread: QAxObject worker thread

  1. #1
    Join Date
    Sep 2010
    Posts
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default QAxObject worker thread

    I'm having an odd issue with a worker thread I've created.
    I have the line 'CoInitialize(0);' in the threads run(). The worker thread basically communicates with EXCEL, so it has a bunch of public member functions to accomplish that. However any of the activeQT calls within those public member functions only operate correctly when called from within the worker thread (specifically in the run() function).
    When the worker thread is in the event loop, none of the ActiveQT calls work (they act as if CoInitialize() has not been called).

    Basically my steps are:
    1) create the worker thread
    2) call the 'start()' on the worker thread (which calls run())
    3) run initializes the QAxObject
    4) once the QAxObjet is created, run calls exec();

    After exec() was called, I was under the impression I could use the workerThreadObject like any other object...

  2. #2
    Join Date
    Jan 2012
    Location
    Argentina
    Posts
    167
    Thanks
    33
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QAxObject worker thread

    http://www.youtube.com/watch?v=JaGqG...ure=plpp_video

    let me know if these videos help im for the 22 but i ve learnt a lot

  3. #3
    Join Date
    Jan 2012
    Posts
    8
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QAxObject worker thread

    I haven't watched the youtube tutorial - so maybe the solution is already there, but this is who I understand the Qt thread 'framework' - and how some guys from Qt also explain it:
    Qt Code:
    1. int main( ... )
    2. {
    3. QApplication oApp( ... );
    4. QThread oMyThread;
    5. MyQObject oMyObject;
    6. oMyObject.moveToThread( &oMyThread );
    7.  
    8. // Important to use AutoConnection or QueuedConnection here!
    9. QMetaObject::invokeMethod( &oMyObject, "SL_DoSomething", Qt::QueuedConnection );
    10.  
    11. oApp.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 
    The point is, that you don't derive from QThread (because so you can attach 10 objects to one thread) but move the object to the thread. Notice also, that only the work in the slots is performed in this thread (and not e.g. the constructor or other direct calls!). So you could place your methods (which were previously in the run() method) into the SL_DoSomething() slot and invoke the method by the signal-slot-mechanism.

    When you call SL_DoSomething() directly (without emitting a signal or using QMetaObject::invokeMethod()) you are still in the main thread.
    Last edited by blueSpirit; 21st January 2012 at 16:15.

Similar Threads

  1. Replies: 3
    Last Post: 20th September 2011, 20:13
  2. Worker thread
    By doggrant in forum Newbie
    Replies: 4
    Last Post: 3rd November 2009, 15:49
  3. Worker thread problem
    By hkvm in forum Qt Programming
    Replies: 4
    Last Post: 6th September 2009, 20:12
  4. Accessing data from a worker thread
    By steg90 in forum Qt Programming
    Replies: 20
    Last Post: 25th May 2007, 10:20
  5. Main thread - worker thread communication.
    By kikapu in forum Newbie
    Replies: 25
    Last Post: 23rd May 2007, 22:09

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.