Results 1 to 12 of 12

Thread: Loading DLL that creates GUI.

  1. #1
    Join Date
    Aug 2007
    Posts
    166
    Thanks
    16
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Loading DLL that creates GUI.

    Hello again...

    The issue this time is really weird. I have a Qt application that works good. I want to extend it via dynamic loading of DLLs. I do not use the Qt way from the documentation because of some reasons...

    Here's what I do: I export a C function from the DLL, then I load that DLL from my Qt application. So far so good, the function in the DLL is called correctly but when comes time the DLL to create some kind of GUI it crashes directly with reason that QApplication must be initialized before QPaintDevice. Well in to the my main() function I initalise QApplication and any GUI that is created by the main program is working good, but I can't create GUI from the DLL. Did someone have any idea how to pass this problem?

  2. #2
    Join Date
    Aug 2007
    Posts
    166
    Thanks
    16
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Loading DLL that creates GUI.

    I forgot to mention - the Qt version is 4.4.3, Compiler is VC++ 2008, OS is Windows XP SP3 and the Qt is build as static. The error I get is "QWidget: Must construct a QApplication before a QPaintDevice" but as I already told QApplication is the first thing intalized in to the main() function of my application. The problem seems to be that in the DLL the qApp pointer is not valid o_0. It is not problem to pass this pointer in to the exported C function when I am loading the DLL but I do not see a way to set it in order to get qApp to return correct pointer. Please help.

  3. #3
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Loading DLL that creates GUI.

    you must create QApplication for providing event loop.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  4. #4
    Join Date
    Aug 2007
    Posts
    166
    Thanks
    16
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Loading DLL that creates GUI.

    But yes I do in to the my application, it is the first thing I do:

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication app( argc, argv );
    4. // code...
    5. return app.exec();
    6. }
    To copy to clipboard, switch view to plain text mode 

    But when I load the DLL using QLibrary to resolve a C exported function and when the times come for the DLL to create any kind of GUI it crashes with the error that I wrote above. Maybe I have to initialize QApplication again in to the DLL ? But then I will have two event loops and perhaps the GUI created via the DLL will be modal but I do not want to be modal. Any solution will be highly appricated.

  5. #5
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Loading DLL that creates GUI.

    are you sure that methods which you export are valid, i.e. not null pointer?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  6. #6
    Join Date
    Aug 2007
    Posts
    166
    Thanks
    16
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Loading DLL that creates GUI.

    Sure, via the DLL I can work with files and do everything that I want, except to create GUI...

    Qt Code:
    1. extern "C" Q_DECL_EXPORT IPlugin* createPlugin( int tlsIndex )
    2. {
    3. g_core = new Chat();
    4.  
    5. g_idxThisThread = tlsIndex;
    6.  
    7. PluginImpl* plugin = new PluginImpl();
    8.  
    9. g_core->setPlugin( plugin );
    10.  
    11. return plugin;
    12. }
    To copy to clipboard, switch view to plain text mode 

    This is the exported function from the DLL and it return correct pointer and the constructor of Chat() will do some stuff but when it come time to create the GUI it crashes.

    The problem is that the DLL can't get valid qApp pointer witch is very strange, in to the main program there is no problem.

  7. #7
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Loading DLL that creates GUI.

    is your app which uses this dll written on Qt?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  8. #8
    Join Date
    Aug 2007
    Posts
    166
    Thanks
    16
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Loading DLL that creates GUI.

    Yes and in it the QApplication is initalized.

  9. #9
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Loading DLL that creates GUI.

    so, why do you use QLibrary insted of adding your dll to your project?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  10. #10
    Join Date
    Aug 2007
    Posts
    166
    Thanks
    16
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Loading DLL that creates GUI.

    What do you mean ? I want to load it dinamyc at runtime, thats why I use QLibrary to resolve the C exported function and activate the DLL in order to do the stuff.

  11. #11
    Join Date
    Aug 2007
    Posts
    166
    Thanks
    16
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Loading DLL that creates GUI.

    Update: same thing happens on linux (.so). I created new QApplication instance in to the DLL but the event loop located in to the main executable have stucked. Please help.

  12. #12
    Join Date
    Aug 2007
    Posts
    166
    Thanks
    16
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Loading DLL that creates GUI.

    With a 15 pages that the search of the forum returned, I finally found topic that answer to my question:
    http://www.qtcentre.org/forum/f-qt-p...ation-631.html

    The other question is even if I pass the pointer of qApp to the DLL from the interface, how I will be able to set correct pointer to QApplication::instance(), I can't find a set method, tomorow I will try some things... If anyone have an idea in the mean time, please let me know.

Similar Threads

  1. Replies: 1
    Last Post: 28th August 2008, 21:18
  2. QImage not loading successively.
    By node_ex in forum Qt Programming
    Replies: 3
    Last Post: 26th July 2008, 13:20
  3. Pixmap height / width without loading it
    By bunjee in forum Qt Programming
    Replies: 1
    Last Post: 29th November 2007, 07:10
  4. Switching static to dynamic ui loading
    By s_a_white in forum Newbie
    Replies: 4
    Last Post: 26th June 2006, 15:57
  5. QSA: loading scripts at runtime
    By seneca in forum Qt Programming
    Replies: 0
    Last Post: 15th February 2006, 15:19

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.