Qt-interest Archive, July 2007
QAxBase: cannot instantiate control
Message 1 in thread
Hi All,
This is my first message on the mailing-list, so thanks to all of those who
share their knowledge here, it has saved my life more than once!
I am trying to create my first application using COM and Qt.
I have created an in-process server with only one class CDummy. Registering
the library works fine (I have also checked in the registry).
Now I'm trying to create an instance of this class inside an application. In
VS2005, I get the following error at runtime:
-----------------------------------------
CoCreateInstance failure (CoInitialize has not been called.)
QAxBase::setControl: requested control
{e2195f4c-620b-4c24-a1af-dc2ee3af1b3f} could not be instantiated
-----------------------------------------
I'm not sure whether I can send the source code attached with this email, so
let me know if you need more details.
Here is my .pro:
-----------------------------------------
TEMPLATE = app
TARGET = apptest
CONFIG += qaxcontainer
TYPELIBS = $$system(dumpcpp -getfile {96732a53-f7cd-477a-a530-7a6a49f12b2b})
isEmpty(TYPELIBS) {
message("type library not found!")
} else {
SOURCES = main.cpp
}
-----------------------------------------
Where 96732a53-f7cd-477a-a530-7a6a49f12b2b is the GUID of the library.
Here is my main.cpp:
-----------------------------------------
#include <QtCore>
#include <QAxObject>
#include "libtest.h"
int main(int argc, char ** argv)
{
QCoreApplication a(argc, argv);
libtestLib::CDummy dummy;
QAxObject object("{e2195f4c-620b-4c24-a1af-dc2ee3af1b3f}");
return a.exec();
}
-----------------------------------------
Where e2195f4c-620b-4c24-a1af-dc2ee3af1b3f is the GUID of the class CDummy.
When I compile for the first time, it creates a libtest.cpp and .h files.
I get the same error in debug or in release mode.
I guess it has something to do with IDL, TBL and LIB files. I've tried to
copy them where my apptest.exe is, but it doesn't solve the issue.
Thanks a lot for reading everything!
Fabien
Message 2 in thread
"Fabien Bénard" <fabien.benard@xxxxxxxxx> wrote in message
news:ffcd66fc0707231138g72a7b327t8eab0cbf9c705731@xxxxxxxxxxxxxxxxx
> Hi All,
>
> This is my first message on the mailing-list, so thanks to all of those
> who
> share their knowledge here, it has saved my life more than once!
>
> I am trying to create my first application using COM and Qt.
>
> I have created an in-process server with only one class CDummy.
> Registering
> the library works fine (I have also checked in the registry).
>
> Now I'm trying to create an instance of this class inside an
> application. In
> VS2005, I get the following error at runtime:
Here is the first piece of advise: If you want to use a QObject in a Qt
application, don't use COM. Either export the QObject subclass from your
DLL (using __declspec(dllexport/dllimport) as usual with DLLs) and link
against it, or use the plugin mechanism that Qt provides.
> -----------------------------------------
> CoCreateInstance failure (CoInitialize has not been called.)
> QAxBase::setControl: requested control
> {e2195f4c-620b-4c24-a1af-dc2ee3af1b3f} could not be instantiated
> -----------------------------------------
As the error says, CoInitialize has not been called.
> I'm not sure whether I can send the source code attached with this
> email, so
> let me know if you need more details.
[...]
> Here is my main.cpp:
>
> -----------------------------------------
> #include <QtCore>
> #include <QAxObject>
> #include "libtest.h"
>
> int main(int argc, char ** argv)
> {
> QCoreApplication a(argc, argv);
>
> libtestLib::CDummy dummy;
> QAxObject object("{e2195f4c-620b-4c24-a1af-dc2ee3af1b3f}");
>
> return a.exec();
> }
QCoreApplication doesn't call CoInitialize - it doesn't know how you want
to initialize COM. QApplication calls OleInitialize, which is required for
the clipboard and drag'n'drop support, but if you use QCoreApplication,
then you need to call CoInitialize and CoUninitialize yourself if you want
to do COM stuff.
Cheers,
Volker
--
[ signature omitted ]
Message 3 in thread
Thanks for your precious answer. So that was something quite obvious, I
should have tried with a QApplication.
I'm a big fan of Qt plug-ins, I tend this mechanism a lot. But in this case,
I need my COM interface to be a singleton shared at runtime by a Qt
Application and a MFC-full-of-COM one, and therefore I won't use a plug-in
for this.
Thanks again for your help, now I can move forward!
Cheers
Fabien
On 24/07/07, Volker Hilsheimer <unwatched@xxxxxxx> wrote:
>
> "Fabien BÃnard" <fabien.benard@xxxxxxxxx> wrote in message
> news:ffcd66fc0707231138g72a7b327t8eab0cbf9c705731@xxxxxxxxxxxxxxxxx
> > Hi All,
> >
> > This is my first message on the mailing-list, so thanks to all of those
> > who
> > share their knowledge here, it has saved my life more than once!
> >
> > I am trying to create my first application using COM and Qt.
> >
> > I have created an in-process server with only one class CDummy.
> > Registering
> > the library works fine (I have also checked in the registry).
> >
> > Now I'm trying to create an instance of this class inside an
> > application. In
> > VS2005, I get the following error at runtime:
>
>
> Here is the first piece of advise: If you want to use a QObject in a Qt
> application, don't use COM. Either export the QObject subclass from your
> DLL (using __declspec(dllexport/dllimport) as usual with DLLs) and link
> against it, or use the plugin mechanism that Qt provides.
>
>
> > -----------------------------------------
> > CoCreateInstance failure (CoInitialize has not been called.)
> > QAxBase::setControl: requested control
> > {e2195f4c-620b-4c24-a1af-dc2ee3af1b3f} could not be instantiated
> > -----------------------------------------
>
>
> As the error says, CoInitialize has not been called.
>
>
> > I'm not sure whether I can send the source code attached with this
> > email, so
> > let me know if you need more details.
>
> [...]
>
> > Here is my main.cpp:
> >
> > -----------------------------------------
> > #include <QtCore>
> > #include <QAxObject>
> > #include "libtest.h"
> >
> > int main(int argc, char ** argv)
> > {
> > QCoreApplication a(argc, argv);
> >
> > libtestLib::CDummy dummy;
> > QAxObject object("{e2195f4c-620b-4c24-a1af-dc2ee3af1b3f}");
> >
> > return a.exec();
> > }
>
>
> QCoreApplication doesn't call CoInitialize - it doesn't know how you want
> to initialize COM. QApplication calls OleInitialize, which is required for
> the clipboard and drag'n'drop support, but if you use QCoreApplication,
> then you need to call CoInitialize and CoUninitialize yourself if you want
> to do COM stuff.
>
>
> Cheers,
> Volker
>
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>