including Qt headers in DLL
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
Re: including Qt headers in DLL
Including <QObject> includes the QObject class definition, but not QThread. For QThread you would include <QThread>. Please consider going through the Qt tutorials.
Re: including Qt headers in DLL
Quote:
Originally Posted by
jpn
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
Re: including Qt headers in DLL
What is the error? What does the corresponding code look like?
Re: including Qt headers in DLL
Here are the errors:
Code:
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:
Code:
void moveToThread
(QThread *thread
);
Re: including Qt headers in DLL
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)?
Re: including Qt headers in DLL
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
Code:
#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:
Code:
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.htm"
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?
Re: including Qt headers in DLL
Compiles fine for me, without "targetver.h", "atlstr.h" (both), and "detours.h" though.