Results 1 to 7 of 7

Thread: QLocalServer without QCoreApplication ?

  1. #1
    Join Date
    Aug 2006
    Posts
    44
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default QLocalServer without QCoreApplication ?

    I noticed that in Qt 4.4, you need to construct a QCoreApplication object before a QLocalServer can be used. QLocalServer::listen() does return true even if the QCoreApplication does not exist, but no connections can be made.

    I have a Qt DLL which is called from non-Qt code, and there I need to use QLocalServer/QLocalSocket to communicate with a Qt program. When I create a dummy QCoreApplication in this DLL, the communication works, otherwise not. This does however seems to be a dangerous practice. I do not need QCoreApplication::exec() or any other related methods.

    The same problem does not occur with TCP sockets. Anyway has any idea how to handle this nicely?

  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: QLocalServer without QCoreApplication ?

    Quote Originally Posted by Raistlin View Post
    I noticed that in Qt 4.4, you need to construct a QCoreApplication object before a QLocalServer can be used. QLocalServer::listen() does return true even if the QCoreApplication does not exist, but no connections can be made.
    That's perfectly normal. All connection oriented classes need events to be delivered to work.

    I do not need QCoreApplication::exec() or any other related methods.
    Hmm... really? Oh.. you probably use waitForNewConnection(), right? It spawns an internal event loop...

    The same problem does not occur with TCP sockets. Anyway has any idea how to handle this nicely?
    Some features need QCoreApplication to work, because there is some initialization code there (for instance plugins are loaded from within the application's constructor, so you need to create it regardless if you're going to use it or not). You might safely create your own application instance, just check if some other code hasn't done it earlier (checking QCoreApplication::instance() for null might be enough).

  3. The following user says thank you to wysota for this useful post:

    Raistlin (9th May 2008)

  4. #3
    Join Date
    Aug 2006
    Posts
    44
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QLocalServer without QCoreApplication ?

    That does make sense, and indeed, there seems no real harm in it when checking QCoreApplication::instance() first. I do see your point about waitForNewConnection() needing an internal event loop, it is just confusing that for QTcpServer the same method does not need it. But then again, the IPC classes are probably just similar to the TCP classes in interface only.

  5. #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: QLocalServer without QCoreApplication ?

    Quote Originally Posted by Raistlin View Post
    it is just confusing that for QTcpServer the same method does not need it.
    It does need an event loop running to work.

  6. #5
    Join Date
    Aug 2006
    Posts
    44
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QLocalServer without QCoreApplication ?

    I meant an instance of CoreApplication, but I guess the event loop is done differently in the network classes and in the local socket classes.

  7. #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: QLocalServer without QCoreApplication ?

    It has nothing to do with the event loop. The event loop is just to make timers work and the mechanism is the same in both cases. The initialization part might be different - for instance the local socket might need access to the thread id or some other application specific stuff. You might check the sources, you know

  8. #7
    Join Date
    Aug 2006
    Posts
    44
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QLocalServer without QCoreApplication ?

    I know, I know . Sometimes I forget I have access to the sources, or I just assume I won't figure it out anyway. But maybe I need to check them more often.

Similar Threads

  1. CLI and QCoreApplication - where to start?
    By soul_rebel in forum Qt Programming
    Replies: 3
    Last Post: 21st October 2007, 14:40
  2. Replies: 5
    Last Post: 24th July 2007, 18:35
  3. QTcpServer in a QCoreApplication
    By xgoan in forum Qt Programming
    Replies: 1
    Last Post: 23rd March 2007, 11:19
  4. QCoreApplication!!!!
    By fellobo in forum Qt Programming
    Replies: 6
    Last Post: 17th January 2007, 01:56
  5. QCoreApplication question
    By barnabyr in forum Newbie
    Replies: 5
    Last Post: 24th March 2006, 20:38

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.