Results 1 to 8 of 8

Thread: Application Library with Qt

  1. #1
    Join Date
    Dec 2012
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Application Library with Qt

    Hello, i try to port a DLL i made in C++ (Win32, without MFC) to Qt but it's a bit hard.

    My DLL is loaded by LoadLibrary from a non-Qt application. But even if it's Qt is portable, it have serious problems with some standards of Windows :|
    Actually, i just want to load my QtGui and handle it like any Qt application. Since the entry point DllMain must return a value to continue, i thought i should make a thread to load it. Here is my problem. In this code :

    Qt Code:
    1. #include "test_ui.h"
    2. #include <windows.h>
    3. #include <process.h>
    4. #include <QApplication>
    5. #include <QMessageBox>
    6.  
    7. void StartThread();
    8.  
    9. BOOL WINAPI DllMain( HMODULE hModule, DWORD dwReason, LPVOID /*lpvReserved*/ )
    10. {
    11. if (dwReason == DLL_PROCESS_ATTACH)
    12. {
    13. DisableThreadLibraryCalls(hModule);
    14. // MessageBoxA(NULL, "Test DllMain", NULL, NULL);
    15. // QMessageBox::information(0, "Test", "Test Qt");
    16. // QtConcurrent::run(StartThread);
    17. //_beginthread((void(*)(void*))StartThread,NULL,NULL);
    18. }
    19. return TRUE;
    20. }
    21.  
    22. void StartThread()
    23. {
    24. MessageBoxA(NULL, "app test", "app test", NULL);
    25. }
    To copy to clipboard, switch view to plain text mode 

    The MessageBoxA in the DllMain works perfectly, the QMessageBox doesn't, the QtConcurrent neither, and same way for _beginthread.
    I tried by the CreateThread function :

    Qt Code:
    1. printf("TestThr address : 0x%.8X\n", (DWORD)TestThr);
    2. HANDLE hThread = CreateThread(NULL,NULL,(LPTHREAD_START_ROUTINE)TestThr, NULL, NULL, NULL);
    3. printf("CreateThread return : %d - GetLastError : %d\n", hThread, GetLastError());
    To copy to clipboard, switch view to plain text mode 

    The console returned me this :

    TestThr address : 0x6F761010
    CreateThread return : 380 - GetLastError : 6
    The GetLastError return ERROR_INVALID_HANDLE while the CreateThread return me an handle, of course the thread is absolutely not loaded ...
    I wanted to try with QtWinMigrate (http://qt.gitorious.org/qt-solutions...r/qtwinmigrate), but it's absolutely not for Qt5 cause there is always much errors.

    I tried with this code : http://stackoverflow.com/a/11056698

    Actually my GUI is loaded EXCEPT :
    1. The dll don't load into the application it should be, but with another one (AutoIt script) it does
    2. The GUI events are not handled at all, except if i minimize then maximize the UI (sort of repaint)


    Well i think i said everything, i use Qt5 final, building with MSVC2010.
    I hope you could help me to get this working.

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Application Library with Qt

    My DLL is loaded by LoadLibrary from a non-Qt application.
    qt widgets are not going to work without a qt event loop - normally from a qt application


    Actually, i just want to load my QtGui and handle it like any Qt application

    then you need a qt application, not a non-qt app and a qt dll.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Dec 2012
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Application Library with Qt

    qt widgets are not going to work without a qt event loop - normally from a qt application
    Then it should be possible to manually create the event loop.
    Some ppl already did it but they never explain how.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Application Library with Qt

    Create a QApplication object and run exec() on it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Dec 2012
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Application Library with Qt

    Create a QApplication object and run exec() on it.
    As you can see i wrote:
    I tried with this code : http://stackoverflow.com/a/11056698
    The QApplication is created, the GUI also but it's not handled at all

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Application Library with Qt

    Well I don't know what you tried. I know what you are supposed to do. If you give me code you tried then I can respond to it. If you give me code of some class someone has written, I don't know how you expect me to answer. Apparently your code differs from theirs if theirs works and yours doesn't.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Dec 2012
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Application Library with Qt

    dllmain.cpp :
    Qt Code:
    1. #include <Windows.h>
    2. #include <QApplication>
    3. #include "AppThread.h"
    4.  
    5. BOOL APIENTRY DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID lpReserved)
    6. {
    7. if (dwReason == DLL_PROCESS_ATTACH)
    8. {
    9. DisableThreadLibraryCalls(hModule);
    10. AppThread * thread = new AppThread();
    11. thread->start();
    12. }
    13.  
    14. return TRUE;
    15. }
    To copy to clipboard, switch view to plain text mode 

    AppThread.h:

    Qt Code:
    1. #ifndef APPTHREAD_H
    2. #define APPTHREAD_H
    3. #include <QThread>
    4. #include <QApplication>
    5. #include <QMessageBox>
    6. #include "TestUI.h"
    7.  
    8. class AppThread : public QThread
    9. {
    10. int result;
    11. void run()
    12. {
    13. int a = 0;
    14. QApplication myQapp(a, NULL);
    15. TestUI w;
    16. w.show();
    17. result = myQapp.exec();
    18. }
    19. public:
    20. AppThread() {}
    21. };
    22.  
    23. #endif // APPTHREAD_H
    To copy to clipboard, switch view to plain text mode 
    Last edited by Exetra; 24th December 2012 at 19:55.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Application Library with Qt

    I don't think it matters that much but try passing correct arguments to QApplication constructor (you should pass at least the executable name). It can also matter that you are using Qt 5. It can also matter what your TestUI contains. It can also matter what the rest of your code does (especially if it interoperates with the UI somehow).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. 64 bit application for Windows using QT library
    By ilgale in forum Qt Programming
    Replies: 10
    Last Post: 4th June 2016, 17:57
  2. Problem with vlc library on QT application
    By andzoff in forum Qt Programming
    Replies: 0
    Last Post: 5th June 2012, 09:09
  3. Calling a .NET library (.dll) from a Qt application
    By magpielover in forum Qt Programming
    Replies: 0
    Last Post: 11th January 2012, 16:21
  4. Replies: 2
    Last Post: 8th July 2010, 08:10
  5. Replies: 0
    Last Post: 22nd February 2010, 17:36

Tags for this Thread

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.