Results 1 to 2 of 2

Thread: Event loop in Qt-based shared library

  1. #1
    Join Date
    Sep 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Event loop in Qt-based shared library

    Hi,

    I'm creating a shared library that is based on a lot of non-GUI Qt components, most notably QHttp. Since the library uses QHttp, I need to have an event loop running. The user of the shared library should be able to instantiate the library object and then continue doing whatever in their code.

    I've read that I need a QCoreApplication instance to have an event loop and that QCoreApplication needs to be started from the main thread. However if I call QCoreApplication::exec() from my main thread, control never goes back to the user of the library. This doesn't give me what I want!

    I've been struggling with the best way to make this work. The best I can get working is to use a QThread (without an event loop) to start QCoreApplication::exec in QThread::run(). I get a warning about QCoreApplication not being created in the main thread, but it's working.

    Any ideas on a better way to implement this? Thanks!

  2. #2
    Join Date
    Sep 2009
    Posts
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Event loop in Qt-based shared library

    Hello, sarabito.

    It is my understanding that "main thread" is not "root process(main() function is running on this thread)".
    I create an other thread(this is gui thread, i.e. = main thread) form root process, and app.exe() is running on the thread.
    Then, I emit signal on root process to qt based object on main thread.
    This method is working now.

    Note that I am using only non-gui qt function. Gui qt function do not test.

    Thanks and sorry for my poor english.


    =======example==========
    void taskPoint(void)
    {
    QCoreApplication();
    ...
    app.exe();
    }

    int main(void)
    {
    create pthread (taskPoint);
    ///
    your programs.
    ///
    return EXIT_SUCCESS;
    }

Similar Threads

  1. Replies: 3
    Last Post: 31st August 2009, 22:50
  2. Replies: 0
    Last Post: 23rd October 2008, 12:43
  3. Qt plug-in for GLib event loop based application
    By profoX in forum Qt Programming
    Replies: 1
    Last Post: 14th June 2008, 14:27
  4. Glib event loop
    By Brandybuck in forum Qt Programming
    Replies: 2
    Last Post: 28th September 2006, 17:19
  5. Workload in a QThread blocks main application's event loop ?
    By 0xBulbizarre in forum Qt Programming
    Replies: 14
    Last Post: 9th April 2006, 21:55

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.