Results 1 to 6 of 6

Thread: QCoreApplication... In a library.

  1. #1
    Join Date
    Dec 2006
    Posts
    160
    Thanks
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question QCoreApplication... In a library.

    Hello guys,

    i'm creating a library for a windev application. Basically, i need this library to spawn a thread, listen for stuff inside this thread, and make results available in a queue.

    So far i've created a bunch of functions exported by the DLL, the first one to make sure a QCoreApplication is created, the second one to destroy it when the windev program is done with the library.
    Qt Code:
    1. QCoreApplication *coreApp = 0;
    2. DLLIFACE void SCPrepareLibrary () {
    3. if (!coreApp) {
    4. int argc = 0;
    5. coreApp = new QCoreApplication(argc, 0);
    6. }
    7. }
    8. DLLIFACE void SCFreeLibrary () {
    9. if (coreApp) {
    10. coreApp->exit();
    11. delete coreApp;
    12. coreApp = 0;
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 

    Now, i'm wondering... i know i've got to call exec on the coreApp so it handles it's event loop, but since i don't want neither of my DLL functions to be blocking, i don't know what to do.
    The solution i have in mind would be to add coreApp->exec() in my preparation function, and ask the developers of the windev application to always call this one in a thread.

    Can someone please tell me the direction to take? Any sample code, any webpage talking about how to make the event loop working in a DLL would be very appreciated...

  2. #2
    Join Date
    Dec 2006
    Posts
    160
    Thanks
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QCoreApplication... In a library.

    Bump...

    i've done more and more testing, and now i'm kind of lost about what i'm supposed to do:
    - i've created a function in my library, which just creates a QCoreApplication and exec() it. This function is called within a thread spawned by the Windev application (Because it needs to be non-blocking).
    - This function is called from within the windev application, inside of a thread.
    - Then, the windev application calls other functions from my library, which try to create Qt objects giving them the QCoreApplication as parent.
    In this case, the qobjects complains they are not in the same thread.

    Of course, if my DLL was a standalone application, i would be able to create a QApplication at the beginning, and then all the QObjects would be children of it, because spawned from the same thread... But i have no control over the Windev application, the only things i'm allowed to do is call my DLL functions from it.

    What's the logic to achieve such a thing then?
    Any kind of help appreciated...
    Thanks!

  3. #3
    Join Date
    Dec 2006
    Posts
    160
    Thanks
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QCoreApplication... In a library.

    Ok in other words: is it possible to get a QCoreApplication object from the "already running" application, which already have a message loop? Is there some way for example to do:
    Qt Code:
    1. QCoreApplication *runningApp = QCoreApplication::fromThread(QThread::currentThread());
    To copy to clipboard, switch view to plain text mode 
    ?

  4. #4
    Join Date
    Dec 2006
    Posts
    160
    Thanks
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QCoreApplication... In a library.

    i've read a bit about the processEvent method of a QApplication... But i hardly can find how can this help me.
    If want to use processEvent, it means it will be called from a function of my DLL, after the Windev application calls it... Which means, i still have no way to poll the device events when the Windev application has control (When the program from my DLL is not running at all, not called, or returned already).
    Also, i'd like to be able to use slots and signal functionality, that's kinda why i choose Qt over the so horrible Win32 API.

    Still looking for an answer.
    Thanks guys,
    Me.

  5. #5
    Join Date
    Jan 2010
    Location
    Ankara - TURKEY
    Posts
    30
    Thanks
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QCoreApplication... In a library.

    Hi hickscorp;

    I have same problem as you have. I have a main MFC application and QT dll which has internal QApplication. When I load qt dll as you expect I have to initialize QApplication and exec it. When I exec qapplication in my dll function, execition flow stops there and never return to my called place to follow other operation in my main MFC application. I can't find any way to solve this wierd problem. You can see my problem from attached image.

    is there anyone who knows how to create Qt Dll library with QApplication but when it loaded it can initialize QApplication and exec it instead of expilicitly exported dll function calling from main application. For example MFC dlls can do this operation and when dll loaded it can create own eventloop implicitly so we have not to call another function to initialize any eventloop.

    Please help me. I have to solve this problem as fast as I can.

    Regards.
    Attached Images Attached Images

  6. #6
    Join Date
    Nov 2009
    Posts
    129
    Thanks
    4
    Thanked 29 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QCoreApplication... In a library.

    Quote Originally Posted by hickscorp View Post
    Can someone please tell me the direction to take? Any sample code, any webpage talking about how to make the event loop working in a DLL would be very appreciated...
    I think some of the ideas and information here:
    Qt/MFC Migration Framework
    could be useful. Regardless of whether your hosting application uses MFC, the methods used to integrate a Qt message loop with an existing message loop might be relevant.

Similar Threads

  1. QLocalServer without QCoreApplication ?
    By Raistlin in forum Qt Programming
    Replies: 6
    Last Post: 9th May 2008, 23:44
  2. QCoreApplication
    By Morea in forum Qt Programming
    Replies: 5
    Last Post: 4th June 2007, 20:58
  3. Use of QCoreApplication
    By moowy in forum Qt Programming
    Replies: 8
    Last Post: 18th May 2007, 09:33
  4. QCoreApplication!!!!
    By fellobo in forum Qt Programming
    Replies: 6
    Last Post: 17th January 2007, 01:56
  5. QCoreApplication problem
    By probine in forum Qt Programming
    Replies: 1
    Last Post: 14th December 2006, 21: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.