Hi All,
This post has also been posted at QtForum.org. So sorry for those who already saw it. I guess that both communities are different enough to give me the right to kind of cross-posting.
I'm trying to develop a COM in-process server and an App that uses it. I'm using Qt 4.3 for Windows, commercial license of course.
Both projects compile well, the only COM interface is correctly registered, but here is what I get at runtime:
QAxBase::setControl: requested control
{e2195f4c
-620b
-4c24
-a1af
-dc2ee3af1b3f
} could not be instantiated
QAxBase::setControl: requested control {e2195f4c-620b-4c24-a1af-dc2ee3af1b3f} could not be instantiated
To copy to clipboard, switch view to plain text mode
This is my first Qt using COM, so I'm not quite sure I'm doing the right thing. Could you guys have a look at what I've done so far? Here is the full source code: TestCOM.zip
First project: Lib
Lib.pro
TEMPLATE = lib
CONFIG += qt warn_on qaxserver dll
contains(CONFIG, static):DEFINES += QT_NODLL
HEADERS = CDummy.h
SOURCES = main.cpp
RC_FILE = c:/qt/4.3.0/src/activeqt/control/qaxserver.rc
DEF_FILE = c:/qt/4.3.0/src/activeqt/control/qaxserver.def
TARGET = TestCOM
TEMPLATE = lib
CONFIG += qt warn_on qaxserver dll
contains(CONFIG, static):DEFINES += QT_NODLL
HEADERS = CDummy.h
SOURCES = main.cpp
RC_FILE = c:/qt/4.3.0/src/activeqt/control/qaxserver.rc
DEF_FILE = c:/qt/4.3.0/src/activeqt/control/qaxserver.def
TARGET = TestCOM
To copy to clipboard, switch view to plain text mode
CDummy.h
#ifndef CDUMMY
#define CDUMMY
#include <QtCore>
{
Q_OBJECT
Q_CLASSINFO("ClassID", "{e2195f4c-620b-4c24-a1af-dc2ee3af1b3f}")
Q_CLASSINFO("InterfaceID", "{88d27a36-8b02-4079-bea2-ebaa083483d2}")
// Constructor, destructor
public:
{
}
// Slots
public slots:
{
}
};
#endif
#ifndef CDUMMY
#define CDUMMY
#include <QtCore>
class CDummy : public QObject
{
Q_OBJECT
Q_CLASSINFO("ClassID", "{e2195f4c-620b-4c24-a1af-dc2ee3af1b3f}")
Q_CLASSINFO("InterfaceID", "{88d27a36-8b02-4079-bea2-ebaa083483d2}")
// Constructor, destructor
public:
CDummy(QObject * parent = 0)
: QObject(parent)
{
}
// Slots
public slots:
QString sayHello(void)
{
return QString("hello world");
}
};
#endif
To copy to clipboard, switch view to plain text mode
main.cpp
#include <QAxFactory>
#include "CDummy.h"
QAXFACTORY_BEGIN("{96732a53-f7cd-477a-a530-7a6a49f12b2b}", "{d4f59aa6-c2e3-4a2e-a1b2-1eb665ec597c}")
QAXCLASS(CDummy)
QAXFACTORY_END()
#include <QAxFactory>
#include "CDummy.h"
QAXFACTORY_BEGIN("{96732a53-f7cd-477a-a530-7a6a49f12b2b}", "{d4f59aa6-c2e3-4a2e-a1b2-1eb665ec597c}")
QAXCLASS(CDummy)
QAXFACTORY_END()
To copy to clipboard, switch view to plain text mode
Second project: App
App.pro
TEMPLATE = app
TARGET = TestCOM
CONFIG += qaxcontainer
TYPELIBS = $$system(dumpcpp -getfile {96732a53-f7cd-477a-a530-7a6a49f12b2b})
isEmpty(TYPELIBS) {
message("TestCOM type library not found!")
} else {
SOURCES = main.cpp
}
TEMPLATE = app
TARGET = TestCOM
CONFIG += qaxcontainer
TYPELIBS = $$system(dumpcpp -getfile {96732a53-f7cd-477a-a530-7a6a49f12b2b})
isEmpty(TYPELIBS) {
message("TestCOM type library not found!")
} else {
SOURCES = main.cpp
}
To copy to clipboard, switch view to plain text mode
main.cpp
#include <QAxObject>
#include <QtCore>
#include "TestCOM.h"
int main(int argc, char ** argv)
{
testcomLib::CDummy dummy;
QAxObject object
("{e2195f4c-620b-4c24-a1af-dc2ee3af1b3f}");
qDebug() << "dummy" << dummy.sayHello();
qDebug() << "object" << object.dynamicCall("sayHello()").toString();
return a.exec();
}
#include <QAxObject>
#include <QtCore>
#include "TestCOM.h"
int main(int argc, char ** argv)
{
QCoreApplication a(argc, argv);
testcomLib::CDummy dummy;
QAxObject object("{e2195f4c-620b-4c24-a1af-dc2ee3af1b3f}");
qDebug() << "dummy" << dummy.sayHello();
qDebug() << "object" << object.dynamicCall("sayHello()").toString();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Cheers!
Fabien
Bookmarks