Results 1 to 6 of 6

Thread: signal/slot mechanism and shared library

  1. #1
    Join Date
    Nov 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default signal/slot mechanism and shared library

    Hi everyone,

    It is the first time I play with shared libraries and I have an issue about the signals and the slots.
    I have an interface ServiceServer that defines two functions :
    Qt Code:
    1. void ServiceServer::emitInitReady(bool is_error, Client* client)
    2. {
    3. qDebug() << "emit init ready";
    4. emit initReady(is_error, client);
    5. qDebug() << "emited";
    6. }
    7.  
    8. void ServiceServer::wrappedInit(bool is_error, Client* client)
    9. {
    10. qDebug() << "wrapped init";
    11. if(is_error)
    12. {
    13. qDebug() << " error";
    14. initError(client);
    15. }
    16. else
    17. {
    18. qDebug() << " ok";
    19. init(client);
    20. }
    21. reset();
    22. }
    To copy to clipboard, switch view to plain text mode 
    Please note that :
    Qt Code:
    1. bool ok = connect(this, SIGNAL(initReady(bool, Client*)), this, SLOT(wrappedInit(bool, Client*)));
    To copy to clipboard, switch view to plain text mode 
    returns true.

    For a "built with the application " implementation, it works and outputs :
    Qt Code:
    1. init
    2. emit init ready
    3. wrapped init
    4. ok
    5. //some stuff
    6. emited
    To copy to clipboard, switch view to plain text mode 
    but for an implementation that is a plugin : it does not work since it outputs that :
    Qt Code:
    1. init
    2. emit init ready
    3. emited
    To copy to clipboard, switch view to plain text mode 
    So the slot was not called.

    the plugin .pro file is :
    Qt Code:
    1. TEMPLATE = lib
    2. TARGET = Chat
    3. DEPENDPATH += .
    4. INCLUDEPATH += .
    5.  
    6. QT += network
    7. QT += sql
    8.  
    9. CONFIG += qt debug dll
    10.  
    11. # Input
    12. HEADERS += Chat.h \
    13. ../client/ServiceGlobal.h \
    14. ../client/ServiceClient.h \
    15. ../common/Service.h \
    16. ../client/ConfigEntry.h \
    17. ../common/WrapperHelper.h \
    18. ../common/Wrapper.h \
    19. ../common/Rights.h \
    20. ../common/WrapperManager.h \
    21. ../common/ServicesContainer.h \
    22. ../client/SingletonFactoryClient.h \
    23. ../client/WrapperManagerClient.h \
    24. ../client/Room0Client.h \
    25. ../common/Room0.h \
    26. ../server/ServiceServer.h \
    27. ../server/InWrapperServer.h \
    28. ../server/CircularBuffer.h
    29.  
    30. SOURCES += Chat.cpp \
    31. ../client/ServiceGlobal.cpp \
    32. ../client/ServiceClient.cpp \
    33. ../client/ConfigEntry.cpp \
    34. ../common/Wrapper.cpp \
    35. ../common/WrapperManager.cpp \
    36. ../client/SingletonFactoryClient.cpp \
    37. ../client/WrapperManagerClient.cpp \
    38. ../client/Room0Client.cpp \
    39. ../server/ServiceServer.cpp \
    40. ../server/InWrapperServer.cpp
    To copy to clipboard, switch view to plain text mode 

    I don't know if the problem has something to do with the shared library but this example make me think that yes.
    Could someone explain me where am I wrong ? Maybe, it is about (un)exported symbols but I run linux and I think that those problems are windows specific.
    Please ask me for more details if I am not clear enough.
    Thanks

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: signal/slot mechanism and shared library

    you don't give any information about how you make your plugin, or how you load the plugin into the main app. please read my sig - issues with your post being the complete + compilable parts.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Nov 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: signal/slot mechanism and shared library

    Sorry, I thought it would be a classic problem. The easiest way to give a complete code is to give all the code, so there is the client side code, the server side code and a plugin : "Chat". The problem appears (at least) on the server side.
    In order to test, you can type make in the root folder then run server_build/server then client_build/client. I use two terminals :
    Qt Code:
    1. tar -xvf program.tar.gz
    2. cd program
    3. make
    4. cd server_build
    5. ./server
    To copy to clipboard, switch view to plain text mode 
    in the second one, after the first step is finished (the server is running)
    Qt Code:
    1. cd program/client_build
    2. ./client
    To copy to clipboard, switch view to plain text mode 
    It is important to be in a *_build folder to test it because relative paths are used.

    The plugin files are in src/services.
    The file src/common/Service.h defines which functions are exported
    To see how the plugin was loaded, see src/server/ServicesFactoryServer.* and src/common/ServicesFactory.*
    You can see the problem when executing in ServiceServer.cpp line 153, this function emits a signal and as shown in th first post the connected function below is not called (wrappedInit). It works for the built-in class that inherits ServiceServer : Room0Server but not for the plugin Chat. ServiceServer itself inherits from InWrapper that is defined at the end of src/common/Wrapper.h.

    Thanks a lot for taking time to help me.
    Attached Files Attached Files

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: signal/slot mechanism and shared library

    Where is your connect() call made?

  5. #5
    Join Date
    Nov 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: signal/slot mechanism and shared library

    In the constructor of ServiceServer (server/ServiceServer.cpp line 20) which is an ancestor of the Chat plugin.

  6. #6
    Join Date
    Nov 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: signal/slot mechanism and shared library [solved]

    It seems to work if the methods called in the slot are not pure virtual.

Similar Threads

  1. signal -slot mechanism!! an interesting problem!!!
    By qt_user in forum Qt Programming
    Replies: 6
    Last Post: 5th August 2010, 11:20
  2. signal -slot mechanism
    By qt_user in forum Qt Programming
    Replies: 2
    Last Post: 30th July 2010, 18:34
  3. When should I use signal/slot mechanism
    By Bryku in forum Newbie
    Replies: 3
    Last Post: 10th February 2010, 22:24
  4. slow signal-slot-mechanism
    By blm in forum Qt Programming
    Replies: 11
    Last Post: 28th October 2008, 17:10
  5. The threaded signal/slot mechanism
    By xbtl in forum Newbie
    Replies: 1
    Last Post: 30th March 2008, 00:07

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.