PDA

View Full Version : including Qt headers in DLL



dave_mm0
15th July 2009, 20:35
hey,

i have a DLL in wich i would like to take a reference to a QObject and manipulate it, without actually creating an interface. So, i included "Qt/qobect.h" and compiled, but the compiler (Visual Studio 2008 pro) gives me syntax erors. It looks like it doesnt recognize the QThread object. How do i use a QObect in my dll? is this even possible? do i have to start my program from a Qt app? im actually trying to set a system-wide hook and get 3rd application QWidgets to manipulate... Any idea how i can use QObject in my dll?

Any help would be greatly appreciated,

Thanks

Dave

jpn
15th July 2009, 20:56
Including <QObject> includes the QObject class definition, but not QThread. For QThread you would include <QThread>. Please consider going through the Qt tutorials.

dave_mm0
15th July 2009, 20:58
Including <QObject> includes the QObject class definition, but not QThread. For QThread you would include <QThread>. Please consider going through the Qt tutorials.

I did try to include QThread, but the same errors appear

jpn
15th July 2009, 21:01
What is the error? What does the corresponding code look like?

dave_mm0
15th July 2009, 21:06
Here are the errors:


1>------ Build started: Project: FroggerDLL, Configuration: Debug Win32 ------
1>Compiling...
1>FTClient.cpp
1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(154) : error C2059: syntax error : 'type'
1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(154) : error C2238: unexpected token(s) preceding ';'
1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2144: syntax error : 'int' should be preceded by ')'
1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2144: syntax error : 'int' should be preceded by ';'
1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2059: syntax error : ')'
1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2208: 'int' : no members defined using this type


the corresponding code looks like this:


QThread *thread() const;
void moveToThread(QThread *thread);

jpn
15th July 2009, 21:12
QThread is properly forward declared in qobject.h. I'm suspecting the problem is where qobject.h is included from. Can you show FTClient.cpp (and .h if there is such)?

dave_mm0
15th July 2009, 21:16
the code from FTClient.cpp and .h doesn't have anything special about it, and they don't even use any Qt references, objects or calls.

QObject is included at the top of FTClient.cpp, right after StdAfx.h. Ill try including it in StdAfx.h.

The only reference to Qt in my code is the include...

Thanks for the fast replies, greatly appreciated

EDIT:
when i include it in stdafx.h, I get 24 errors. Here is what my stdafx.h looks like



#pragma once

#include "targetver.h"

#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
// Windows Header Files:
#include <windows.h>
#include <atlstr.h>

#include <TCHAR.H> // Generic text routines
#include <richedit.h> // Standard Win32 rich edit control
#include <psapi.h> // Needed for GetModuleFileNameEx.
#include <atlstr.h>

// TODO: reference additional headers your program requires here
#include <string> // STL string implemenation
#include <map>
#include <deque>
#include <vector>
#include <detours.h>

#include "Qt/qobject.h"


and here are the errors:


1>------ Build started: Project: FroggerDLL, Configuration: Debug Win32 ------
1>Compiling...
1>stdafx.cpp
1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(154) : error C2059: syntax error : 'type'
1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(154) : error C2238: unexpected token(s) preceding ';'
1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2144: syntax error : 'int' should be preceded by ')'
1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2144: syntax error : 'int' should be preceded by ';'
1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2059: syntax error : ')'
1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2208: 'int' : no members defined using this type
1>Build log was saved at "file://c:\Users\Dave\Documents\Visual Studio 2008\Projects\Frogger\FroggerDLL\Debug\BuildLog.ht m"
1>FroggerDLL - 6 error(s), 0 warning(s)
2>------ Build started: Project: FroggerConsole, Configuration: Debug Win32 ------
2>Compiling...
2>Main.cpp
2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(154) : error C2059: syntax error : 'type'
2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(154) : error C2238: unexpected token(s) preceding ';'
2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2144: syntax error : 'int' should be preceded by ')'
2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2144: syntax error : 'int' should be preceded by ';'
2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2059: syntax error : ')'
2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2208: 'int' : no members defined using this type
2>ActionPerformer.cpp
2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(154) : error C2059: syntax error : 'type'
2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(154) : error C2238: unexpected token(s) preceding ';'
2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2144: syntax error : 'int' should be preceded by ')'
2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2144: syntax error : 'int' should be preceded by ';'
2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2059: syntax error : ')'
2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2208: 'int' : no members defined using this type
2>FTActionPerformer.cpp
2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(154) : error C2059: syntax error : 'type'
2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(154) : error C2238: unexpected token(s) preceding ';'
2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2144: syntax error : 'int' should be preceded by ')'
2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2144: syntax error : 'int' should be preceded by ';'
2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2059: syntax error : ')'
2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2208: 'int' : no members defined using this type
2>Generating Code...



EDIT #2:
the errors I now get are when the compiler tries to compile stdafx.h, wich is in my DLL project, and the other 3 sets of 6 errors are in other headers/cpp wich are in my console project. I will try replacing my console project for a Qt project. Do i have to compile my DLL with Qmake?

jpn
15th July 2009, 21:39
Compiles fine for me, without "targetver.h", "atlstr.h" (both), and "detours.h" though.