Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can I create QApplication in DLL?
Forum Updated to NodeBB v4.3 + New Features

Can I create QApplication in DLL?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 5 Posters 8.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mady
    wrote on last edited by
    #1

    I am developing a Qt library (.dll) for my client application. My DLL has some GUI stuffs like trayIcon, traymenu,.... and doing some network operations like downloading XML files and parsing them, etc.

    So far I have developed it as executable app and created one instance of QApplication in main and waited on app.exec() but wondering if my DLL can create QApplication for its own use.

    Few queries as below,

    1. Whose responsibility to create an instance of QApplication, my dll or my client App?
    2. If I wanted to keep QApplication inside my DLL can it be possible? If yes how to do that and what all cases I have to take care?
    3. If my client application can create an instance of QApplication can my dll use that?
    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Ad. 3. Yes, qApp pointer is available even in libraries.

      I have some ideas, but am not sure about other 2 questions, though, and don't want to make you make a mistake :) So I won't answer them.

      (Z(:^

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        You might get the QApplication pointer from your DLL by means of a static (factory) method. Even if your complete application code is inside the DLL, you will always need a main function in an application binary in that calls that DLL code. So, conceptually there is not much difference between instantiating a QApplication in main() or calling runThatFancyApp(argc, argv) in the DLL.

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dor666
          wrote on last edited by
          #4

          (sorry for resurrecting old thread, but I must disagree in one case)

          Watch out on windows, If you call qApplication destructor from DllMain (with DLL_PROCESS_DETACH) you whole application can hang due to calling OleUninitialize in qtSource.

          MSDN says not to call OleUninitialize in DllMain
          http://msdn.microsoft.com/en-us/library/windows/desktop/ms691326(v=vs.85).aspx

          Just remove qApplication before DLL_PROCESS_DETACH (this might be a problem if you do not have access to host application source)

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            @dor666, I think the question was more generic, not the special case of using DllMain function entry. There's "plenty of hints on the net not to (ab-) use DllMain ":https://blogs.msdn.com/b/larryosterman/archive/2004/04/23/118979.aspx?Redirected=true

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved