views:

617

answers:

3

Hi, I have a dynamic library that works fine, and I would like to use a QObject in it. After including the "qobject.h" header, I compile adn evrything is fine. But when I try declaring a QObject, the compiler always gives me a "identifier not found" error. I tried foward eclaration of the QObject class, it did not help. It's weird because visual studio's intellisense is working when I use Qt in my dll (ex.: when i declare a QObject, visual sdio shows me the functions available to my QObject). Is there anything special I have to do to use Qt in a dynamic library? Do I have to compile it with qmake now that I'm using a QObject?

thanks for the help

Dave

EDIT: the problems seems only to occur after I include stdafx.h. If I try to include the Qt headers after Stdafx.h, my library fails to compile, giving me syntax errors. If I use a Qt reference before including Stdafx.h, it compiles and runs fine, but it's kind of useless, because I can't use Qt refenrences in my existing code.

1>c:\users\dave\documents\visual studio 2008\projects\frogger\froggerdll\ftclient.cpp(47) : error C2653: 'QWidget' : is not a class or namespace name
1>c:\users\dave\documents\visual studio 2008\projects\frogger\froggerdll\ftclient.cpp(47) : error C3861: 'find': identifier not found

the line in question is QWidget::find(hwnd); and I am including QWidget

A: 

Have you installed the integration between VS and Qt? I do believe you need that (in lieu of using qmake) for both applications and libraries. As for the stdafx issue, I imagine you must probably be running into conflicting macros between that header and the qobject one (but if I read you right you can bypass the issue by including them in this order, qobject first and stdafx next -- is that correct?). [[Apparently not, per the OP's latest comment]].

Edit: some instructions on making the VS/Qt integration work are here, if you're using the LGPL version of Qt 4.5 -- otherwise I believe the integration product is a commercial offering. (If you don't desperately need some specific aspects of Visual Studio, you might alternatively simplify your life by using Qt Creator instead, but I do realize that VS and its underlying C++ compiler may be preferable in other respects).

Alex Martelli
well I can bypass it, by including them in the right order, but then I cannot use a QObject, so it doesn't really solve my problem. I'll try installing the intergration. Is there any particular steps I have to take, or it should compile fine after that?
David Menard
I thought "compile and runs fine" meant just that -- maybe you want to edit your question again to clarify it doesn't. I'm editing my answer to add a pointer to instructions for integration.
Alex Martelli
I tried installing the integration with the instructions above, I still get the same errors
David Menard
A: 

Please show the code and the specific compile errors.

Intransigent Parsnip
Edited my question
David Menard
A: 

Since nothing here worked, I will be porting my code to a Qt dll.

Thanks for the help!

David Menard