PDA

View Full Version : ActiveQt, setControl method.



sky
3rd June 2011, 13:14
Hi All,

I am trying to wrap an activeX object with QAxWidget. The activeX object raises some events like "dataReady()". I am trying to connect these events to some slots in Qt. What I have observed is that if I call the connect method before the setControl then the connect method fails saying there is no such signal. But if I call the connect after the setControl then the connect call is successful.



b = connect(m_pAxWidget, SIGNAL(dataReady()), this, SLOT(check()));
setControl( CLASSID );

The above fails with:
Object::connect: No such signal QAxBase::CardDataChanged() in MainWidget.cpp:16




setControl( CLASSID );
b = connect(m_pAxWidget, SIGNAL(dataReady()), this, SLOT(check()));

This one is successful.

Does this mean that Qt is able to add signals and slots at run time? if so can anyone briefly describe the mechanism and let me know of the source code files or any place else where I can read about this.

If adding signals and slots at run time is possible then:

Is there a way I can propagate the signals emitted from a member object to the parent object at run time? I mean I don't know what signal the member object will emit but whatever it emits the parent should also emit.
eg:

class a
{
QAxWidget b;
}

Now I don't know what signals b emits but I want a mechanism such that whatever b emits a also should emit.

I hope I am clear.

Sky

dbzhang800
6th June 2011, 07:20
The signals and slots mechanism implements using Qt's meta-object System.

Normally, when you want to add new signals or slots to a class, your add the macro Q_OBJECT to the class, then run moc to generate a moc_xxx.cpp file.

However, although QAxObject and QAxWidget is QObject's subclass, and new signals and slots added to them. But they donot contain an Q_OBJECT in source code, so you cannot run the program moc to generate meta-object.

Then, where is the meta-object for QAxObject and QAxWidget?


const QMetaObject *QAxBase::metaObject() const {
...
if (!d->ptr || !d->useMetaObject) {
if (qObject()->isWidgetType())
return &qaxwidget_staticMetaObject;
return &qaxobject_staticMetaObject;
}
MetaObjectGenerator generator((QAxBase*)this, d);
return generator.metaObject(parentObject);
}


MetaObjectGenerator will load infomation from the type lib of your AcitveX, then it create an QMetaObject which contain the signals.

If your want to know how it works, you had better read the source code of the ActiveQt module. And of course, it is very complex.