Results 1 to 12 of 12

Thread: Share QApplication instance (exe and dll)

  1. #1
    Join Date
    Oct 2007
    Location
    Atlanta, GA
    Posts
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question Share QApplication instance (exe and dll)

    I'm building an application that links to a dll that uses QHttp to do some work. Both the exe and the dll link to Qt 4.3.2 static libs. The problem I'm running into is that QHttp in the dll does not share the same QApplication object as the UI in the exe. It isn't able to process events. Is there a way to solve this problem, since I can't just create a new QApplication instance?

  2. #2
    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: Share QApplication instance (exe and dll)

    You should retrieve the application instance by using the static method QCoreApplication::instance() (or qApp global pointer).

  3. #3
    Join Date
    Oct 2007
    Location
    Atlanta, GA
    Posts
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Unhappy Re: Share QApplication instance (exe and dll)

    That doesn't seem to work, since it will not be the same instance (a problem with sharing singletons across dlls).

  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: Share QApplication instance (exe and dll)

    Don't link to static libs then. It's not a problem of sharing singletons across dlls, but across static libs. Shared objects would work fine.

  5. #5
    Join Date
    Oct 2007
    Location
    Atlanta, GA
    Posts
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Share QApplication instance (exe and dll)

    Quote Originally Posted by wysota View Post
    It's not a problem of sharing singletons across dlls, but across static libs
    You are correct. That's what I should have said above. I would love to just use the Qt dynamic libs but that's not an option for the project I'm working on. So... I'm still looking for a way to solve this issue.

  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: Share QApplication instance (exe and dll)

    If you link to Qt libs two times, you are wasting space. What is the reason of linking both the executable and the shared object against static Qt libraries?

  7. #7
    Join Date
    Oct 2007
    Location
    Atlanta, GA
    Posts
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Share QApplication instance (exe and dll)

    Thanks for helping me out on this one. The shared library is used by the Qt exe that I mentioned and another non-Qt application. When I launch from the non-Qt app I just create a QCoreApplication object to process events while the lib does its work.

    Quote Originally Posted by wysota
    What is the reason of linking both the executable and the shared object against static Qt libraries?
    The Qt based exe links to (this is off the top of my head, I'm not near the machine I'm working on this... heh... it's the weekend ):

    qmain
    qtcore
    qtgui

    The shared lib links to:

    qtcore
    qtnetwork
    qtxml

    Is there something I'm doing wrong here?

    Once again, thanks for staying with me on this one.

  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: Share QApplication instance (exe and dll)

    You didn't understand my question. You said that you have to link statically. Why?

  9. #9
    Join Date
    Oct 2007
    Location
    Atlanta, GA
    Posts
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Share QApplication instance (exe and dll)

    Quote Originally Posted by wysota View Post
    You said that you have to link statically. Why?
    It was a matter of not wanting to ship the Qt Dlls. This is not a decision that I had a big part in.

    I will try to bring up the idea of using dynamic libraries instead of trying to link statically. Thanks for all your help.

  10. #10
    Join Date
    Apr 2006
    Location
    San Francisco, CA
    Posts
    186
    Thanks
    55
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Share QApplication instance (exe and dll)

    how about instead of linking to a dll, just building another stand-alone exe (that will do the QHttp work) that you just launch from your main exe?
    Software Engineer



  11. #11
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Share QApplication instance (exe and dll)

    I'd suggest linking the DLL against ALL the Qt libs needed (by both app and dll itself) and then just linking the executable against the DLL but I'm not sure static linking would ensure all requested symbols would be embedded into the DLL....
    Current Qt projects : QCodeEdit, RotiDeCode

  12. The following user says thank you to fullmetalcoder for this useful post:

    gfunk (18th October 2007)

  13. #12
    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: Share QApplication instance (exe and dll)

    Quote Originally Posted by cquinones View Post
    It was a matter of not wanting to ship the Qt Dlls.
    You ship other DLLs - like plugins, so what's the reason for not shipping Qt libs? This would reduce the volume of the final package. You can even strip down the Qt DLLs of everything you don't need if you want to to further reduce the size of the package.

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.