Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 2

Qt-interest Archive, February 2007
Qt4: crash with QObject::connect() in application startup code


Message 1 in thread

Platform is Windows XP SP2, compiler is VS2005 w/o SP, Qt is 4.2.2
commercial

I experience crashes in application startup code (initialization of
static data) due to calls to QObject::connect(). I traced the crash down
to the moc generated files. Here it seems that static data in the moc
file is not yet initialized when referred to.

My moc_....cpp looks like this:

<CODE>
...

static const uint qt_meta_data_ICSimpleNotifier[] = {
 // content:
       1,       // revision
       0,       // classname
       0,    0, // classinfo
       1,   10, // methods
       0,    0, // properties
       0,    0, // enums/sets
 // signals: signature, parameters, type, tag, flags
      18,   17,   17,   17, 0x05,
       0        // eod
};

static const char qt_meta_stringdata_ICSimpleNotifier[] = {
    "ICSimpleNotifier\0\0activated()\0"
};

const QMetaObject ICSimpleNotifier::staticMetaObject = {
    { &QObject::staticMetaObject, qt_meta_stringdata_ICSimpleNotifier,
      qt_meta_data_ICSimpleNotifier, 0 }
};

const QMetaObject *ICSimpleNotifier::metaObject() const
{
    return &staticMetaObject;
}
...
</CODE>

Whenever QObject::connect() is called, it calls metaObject() of the
sender. However, in my case the static data seems to be not yet
initialized when the call occurs. The returned QMetaObject contains NULL
pointers for both stringdata and data.

Qt3 did not show this problem, as it does not use static data as shown
above.

Has anyone else experienced this problem? Could anyone think of a
solution without the need to get rid of calling QObject::connect() from
my startup code?

Best Regards / Mit freundlichen Grüßen
Rainer Wiesenfarth

-- 
 [ signature omitted ] 

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


Message 2 in thread

From the looks of things, it looks like a QObject descendant is being
declared statically that connects objects.
If possible, use the Q_GLOBAL_STATIC macro instead to have it
automatically declare a singleton for you, which should help avoid this
situation. Grabbing a backtrace if possible from the crash point should
give you an idea which object is responsible for this, if not which
variable.

Good hunting,
Bill.

Rainer Wiesenfarth wrote:
> Platform is Windows XP SP2, compiler is VS2005 w/o SP, Qt is 4.2.2
> commercial
>
> I experience crashes in application startup code (initialization of
> static data) due to calls to QObject::connect(). I traced the crash down
> to the moc generated files. Here it seems that static data in the moc
> file is not yet initialized when referred to.
>
> My moc_....cpp looks like this:
>
> <CODE>
> ...
>
> static const uint qt_meta_data_ICSimpleNotifier[] = {
>  // content:
>        1,       // revision
>        0,       // classname
>        0,    0, // classinfo
>        1,   10, // methods
>        0,    0, // properties
>        0,    0, // enums/sets
>  // signals: signature, parameters, type, tag, flags
>       18,   17,   17,   17, 0x05,
>        0        // eod
> };
>
> static const char qt_meta_stringdata_ICSimpleNotifier[] = {
>     "ICSimpleNotifier\0\0activated()\0"
> };
>
> const QMetaObject ICSimpleNotifier::staticMetaObject = {
>     { &QObject::staticMetaObject, qt_meta_stringdata_ICSimpleNotifier,
>       qt_meta_data_ICSimpleNotifier, 0 }
> };
>
> const QMetaObject *ICSimpleNotifier::metaObject() const
> {
>     return &staticMetaObject;
> }
> ...
> </CODE>
>
> Whenever QObject::connect() is called, it calls metaObject() of the
> sender. However, in my case the static data seems to be not yet
> initialized when the call occurs. The returned QMetaObject contains NULL
> pointers for both stringdata and data.
>
> Qt3 did not show this problem, as it does not use static data as shown
> above.
>
> Has anyone else experienced this problem? Could anyone think of a
> solution without the need to get rid of calling QObject::connect() from
> my startup code?
>
> Best Regards / Mit freundlichen Grüßen
> Rainer Wiesenfarth
>
>   


-- 
 [ signature omitted ] 

Message 3 in thread

Hi Bill,

On Monday 05 February 2007 23:34, Bill KING wrote:
> If possible, use the Q_GLOBAL_STATIC macro instead to have it
> automatically declare a singleton for you, which should help avoid this
> situation. 

Be careful when recommending Q_GLOBAL_STATIC to people, it's not documented as 
part of the API (since it's not meant to be a the proper way to declare a 
singleton). 

:)

-- 
 [ signature omitted ]