[Qt-interest] [OT] RE: Qt::AutoConnection fails
Oliver.Knoll at comit.ch
Oliver.Knoll at comit.ch
Wed Apr 15 09:12:33 CEST 2009
Andreas Pakulat wrote on Tuesday, April 14, 2009 6:31 PM:
> ...
> At least in 4.0 there was no such warning from ::connect() and the
> code that determines queued vs. direct when Qt::AutoConnection has
> been used is also the same in 4.0 as in 4.5.
Okay, let's assume I had some weird memory leak in my brain and this example came through a dark hole into my CPU ;) I really have no clue where I got this example from, so from now on the following discussion is purely academic and of no relevance to the OP's original question!
> 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.
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? :)
Cheers, Oliver
--
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22
More information about the Qt-interest-old
mailing list