[Qt-interest] [OT] RE: Qt::AutoConnection fails

Andreas Pakulat apaku at gmx.de
Wed Apr 15 09:16:50 CEST 2009


On 15.04.09 09:12:33, Oliver.Knoll at comit.ch wrote:
> Andreas Pakulat wrote on Tuesday, April 14, 2009 6:31 PM:
> > And your example is incomplete. Wether a direct or queued connection
> > is used depends on where MyObject is being created, not where the
> > connect call is placed. If MyObject is created in the MyThread
> > constructor then it'll be a direct connection because both the thread
> > object as well as its member are being created inside the "main"
> > thread and hence both have the same thread as owning thread. If
> > however MyObject is created inside ::run() then it'll have MyThread
> > as owning thread and hence a queued connection will be used.
> 
> That's correct, but have a look at my class definition again:
> 
> class MyThread : public QThread {
>     Q_OBJECT
>   public:
>     MyThread();
>   signals:
>     void foo();
>   protected:
>     virtual void run();
>   private:
>     // object is statically allocated!
>     MyObject m_myObject;
>   };
> 
> I was a bit too lazy to use a new() allocation of m_myObject (dynamic allocation), so whatever thread instantiates class MyThread also instantiates m_myObject. In other words: m_myObject belongs to the thread  (for example the "main" thread) which creates MyThread.

Ooops.

> And this thread is then different from the one which is created when MyThread starts running in the run() method.
> 
> So given my obviously wrong assumption that connect() would determine the kind of connection at least my example should be correct, no? :)

Of course.

Andreas

-- 
You will be married within a year.



More information about the Qt-interest-old mailing list