Results 1 to 8 of 8

Thread: including Qt headers in DLL

  1. #1
    Join Date
    Jul 2009
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Lightbulb 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
    Last edited by dave_mm0; 15th July 2009 at 20:46.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default 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.
    J-P Nurmi

  3. #3
    Join Date
    Jul 2009
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: including Qt headers in DLL

    Quote Originally Posted by jpn View Post
    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

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: including Qt headers in DLL

    What is the error? What does the corresponding code look like?
    J-P Nurmi

  5. #5
    Join Date
    Jul 2009
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: including Qt headers in DLL

    Here are the errors:

    Qt Code:
    1. 1>------ Build started: Project: FroggerDLL, Configuration: Debug Win32 ------
    2. 1>Compiling...
    3. 1>FTClient.cpp
    4. 1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(154) : error C2059: syntax error : 'type'
    5. 1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(154) : error C2238: unexpected token(s) preceding ';'
    6. 1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2144: syntax error : 'int' should be preceded by ')'
    7. 1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2144: syntax error : 'int' should be preceded by ';'
    8. 1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2059: syntax error : ')'
    9. 1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2208: 'int' : no members defined using this type
    To copy to clipboard, switch view to plain text mode 


    the corresponding code looks like this:

    Qt Code:
    1. QThread *thread() const;
    2. void moveToThread(QThread *thread);
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default 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)?
    J-P Nurmi

  7. #7
    Join Date
    Jul 2009
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default 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


    Qt Code:
    1. #pragma once
    2.  
    3. #include "targetver.h"
    4.  
    5. #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
    6. // Windows Header Files:
    7. #include <windows.h>
    8. #include <atlstr.h>
    9.  
    10. #include <TCHAR.H> // Generic text routines
    11. #include <richedit.h> // Standard Win32 rich edit control
    12. #include <psapi.h> // Needed for GetModuleFileNameEx.
    13. #include <atlstr.h>
    14.  
    15. // TODO: reference additional headers your program requires here
    16. #include <string> // STL string implemenation
    17. #include <map>
    18. #include <deque>
    19. #include <vector>
    20. #include <detours.h>
    21.  
    22. #include "Qt/qobject.h"
    To copy to clipboard, switch view to plain text mode 


    and here are the errors:

    Qt Code:
    1. 1>------ Build started: Project: FroggerDLL, Configuration: Debug Win32 ------
    2. 1>Compiling...
    3. 1>stdafx.cpp
    4. 1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(154) : error C2059: syntax error : 'type'
    5. 1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(154) : error C2238: unexpected token(s) preceding ';'
    6. 1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2144: syntax error : 'int' should be preceded by ')'
    7. 1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2144: syntax error : 'int' should be preceded by ';'
    8. 1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2059: syntax error : ')'
    9. 1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2208: 'int' : no members defined using this type
    10. 1>Build log was saved at "file://c:\Users\Dave\Documents\Visual Studio 2008\Projects\Frogger\FroggerDLL\Debug\BuildLog.htm"
    11. 1>FroggerDLL - 6 error(s), 0 warning(s)
    12. 2>------ Build started: Project: FroggerConsole, Configuration: Debug Win32 ------
    13. 2>Compiling...
    14. 2>Main.cpp
    15. 2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(154) : error C2059: syntax error : 'type'
    16. 2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(154) : error C2238: unexpected token(s) preceding ';'
    17. 2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2144: syntax error : 'int' should be preceded by ')'
    18. 2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2144: syntax error : 'int' should be preceded by ';'
    19. 2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2059: syntax error : ')'
    20. 2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2208: 'int' : no members defined using this type
    21. 2>ActionPerformer.cpp
    22. 2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(154) : error C2059: syntax error : 'type'
    23. 2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(154) : error C2238: unexpected token(s) preceding ';'
    24. 2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2144: syntax error : 'int' should be preceded by ')'
    25. 2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2144: syntax error : 'int' should be preceded by ';'
    26. 2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2059: syntax error : ')'
    27. 2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2208: 'int' : no members defined using this type
    28. 2>FTActionPerformer.cpp
    29. 2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(154) : error C2059: syntax error : 'type'
    30. 2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(154) : error C2238: unexpected token(s) preceding ';'
    31. 2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2144: syntax error : 'int' should be preceded by ')'
    32. 2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2144: syntax error : 'int' should be preceded by ';'
    33. 2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2059: syntax error : ')'
    34. 2>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2208: 'int' : no members defined using this type
    35. 2>Generating Code...
    To copy to clipboard, switch view to plain text mode 



    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?
    Last edited by dave_mm0; 15th July 2009 at 21:23.

  8. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: including Qt headers in DLL

    Compiles fine for me, without "targetver.h", "atlstr.h" (both), and "detours.h" though.
    J-P Nurmi

Similar Threads

  1. spaning the headers in the QTableView
    By ru_core in forum Qt Programming
    Replies: 6
    Last Post: 11th June 2013, 13:17
  2. Installing headers
    By MathStuf in forum Qt Programming
    Replies: 2
    Last Post: 30th June 2008, 11:05
  3. deleting selected headers
    By ru_core in forum Qt Programming
    Replies: 3
    Last Post: 16th April 2008, 07:53
  4. How to make headers fixed sized? (QTableWidget)
    By macias in forum Qt Programming
    Replies: 4
    Last Post: 13th August 2007, 15:57
  5. [custom widget] What about private headers ?
    By lauranger in forum Qt Programming
    Replies: 3
    Last Post: 18th November 2006, 23:14

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.