Results 1 to 4 of 4

Thread: Launching Multiple QApplication within a DLL

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Launching Multiple QApplication within a DLL

    s there a way to call QApplication across multiple threads within a single dll?
    No, and it has to do with the event loop, QApplication is designed as a singleton.

    What you can do is spawn separate processes using QProcess.
    You wont have a direct access to their events (as you mentioned you need) but you can overcome it the usual way for this kind of a scenario by using an IPC mechanism of your choice.
    This will involve code that inspects the events and dispatches them (or rather, data about them) over the IPC.

    Or, you could go about implementing your own "application" object building it around a QEventLoop - not something for beginners.

    However, reading your post I am not sure you actually need multiple QApplications, what you seem to need is merely "multiple UI's."
    I am putting quotes because you only really have one UI per QApplication - which can be made of many views and windows etc.
    You could have threads each doing his thing, and talking to a different window or UI - and all these threads can share the even processing of your QApplication, each thread can be killed or spawned.
    When the last thread exists, you can close your QApplication too.
    To be clear:
    your threads will drive the business logic, but they will be talking to a UI living the in the QApplication gui thread.

    None of the above options are trivial, but the last one with threads seems to me the most sensible, and probably the most practical to implement.
    Last edited by high_flyer; 15th October 2017 at 23:52.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  2. #2
    Join Date
    Mar 2017
    Posts
    9
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Launching Multiple QApplication within a DLL

    Thanks for the input high_flyer.

    I get what you are saying, and I have tried to implement it to some extent, but ran into issues.

    Options I see.
    1. Can I use a Qthread.exec() to run the guis instead of QApplication?
    2. Can I use a common thread to create the windows and qapplication for all the classes?
    3. Can I make my own processevents() loop?
    4. Can I use QEventLoop?

    Are there any examples of doing this out there?

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Launching Multiple QApplication within a DLL

    1. Can I use a Qthread.exec() to run the guis instead of QApplication?
    No, the UI has to live in the QApplication UI main thread (the usual case, as I said, you could implement your own QApplication but do you really want/need to?)
    You could have your thread instruct creation of UI's in the main thread however.

    2. Can I use a common thread to create the windows and qapplication for all the classes?
    You already have that - the main UI thread.

    3. Can I make my own processevents() loop?
    4. Can I use QEventLoop?
    Yes, by using QEventLoop.

    Are there any examples of doing this out there?
    I don't know (maybe someone else here does).
    I would look in QDialog for example, (there are some other classes which have their own event loop as well) and try to get the right way of using it from there.
    A short google search provided this which I think might be interesting as well:
    https://www.qtdeveloperdays.com/2013...Event_Loop.pdf
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Replies: 2
    Last Post: 1st August 2011, 06:30
  2. Segmentation fault after Launching Qt app
    By payal in forum Qt Programming
    Replies: 2
    Last Post: 3rd March 2010, 19:05
  3. Launching a PDF in platform independant way
    By JPNaude in forum Qt Programming
    Replies: 2
    Last Post: 30th September 2008, 19:04
  4. Launching external web browser from within Qt App
    By JimDaniel in forum Qt Programming
    Replies: 1
    Last Post: 31st October 2007, 18:22
  5. Launching problem
    By Salazaar in forum Newbie
    Replies: 5
    Last Post: 29th October 2007, 11:18

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
  •  
Qt is a trademark of The Qt Company.