Results 1 to 3 of 3

Thread: CMake3.6 / VS2015 / Qt5.7 - lost in function-pointer based signals/slots across DLLs

  1. #1
    Join Date
    Dec 2016
    Location
    New England, US
    Posts
    31
    Thanks
    6
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default CMake3.6 / VS2015 / Qt5.7 - lost in function-pointer based signals/slots across DLLs

    Some details on my configuration + the problem:
    • I use the CMake Windows_Export_All_Symbols feature as explained here, and I don't worry about declspecs (dllimport/dllexport) any more.
    • As the title says, I use the new function-pointer approach for signals/slosts, to ensure type-safety at compile time.
    • When the signals/slots are in the same DLL, things are fine. Otherwise I get
      Qt Code:
      1. unresolved external symbol "public: static struct QMetaObject const top::level1::mtree::MyWidget::staticMetaObject"
      To copy to clipboard, switch view to plain text mode 
      - I don't believe namespace is a problem.
    .

    What have I researched, discovered and tried so far?
    • As stated in the CMake blog, the dll export feature of CMake doesn't work for static const members. They recommend "dllimport/dllexport" on those variables.
    • So I tried the solution from Qt (also mentioned in other blogs including this forum), like so:


    Qt Code:
    1. #ifdef myWidget_DLL
    2. #define myWidget_DLL_EXPORT Q_DECL_EXPORT
    3. #else
    4. #define myWidget_DLL_IMPORT Q_DECL_IMPORT
    5. #endif
    6.  
    7. class myWidget_DLL_EXPORT MyWidget : public QDockWidget { ... };
    8.  
    9. # CMakeLists.txt entry to activate my macros
    10. add_definitions (-DmyWidget_DLL)
    To copy to clipboard, switch view to plain text mode 
    But this doesn't work because CMake already does something like this, and myWidget_DLL_EXPORT in the class declaration is treated like a class/type, and not a macro.

    So, how do I selectively export / import
    Qt Code:
    1. QMetaObject const top::level1::mtree::MyWidget::staticMetaObject
    To copy to clipboard, switch view to plain text mode 
    the variable found in moc_MyWidget.cpp. I tried exporting it from the moc_ file itself as a prototype, but it doesn't work - the compiler thinks I am trying to redefine the static meta object. What am I doing wrong? How do I resolve this. The constraint is that I don't want to close the CMake dll export feature, unless that is my last resort. Any pointers or suggestions is greatly appreciated.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: CMake3.6 / VS2015 / Qt5.7 - lost in function-pointer based signals/slots across D

    I'm not so sure your class declaration is correct - you add the myWidget_DLL_EXPORT macro, but that will only be defined when you are building the DLL (i.e. myWidget_DLL defined). At import time, this macro is undefined and should lead to a compile error. I don't see any place where you use myWidget_DLL_IMPORT.

    And you have remembered to add the Q_OBJECT macro to your class definition, right?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

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

    NameRakes (7th January 2017)

  4. #3
    Join Date
    Dec 2016
    Location
    New England, US
    Posts
    31
    Thanks
    6
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: CMake3.6 / VS2015 / Qt5.7 - lost in function-pointer based signals/slots across D

    There is always the silly typo (which the developer alone doesn't see) is there to humble you. I had unintentionally defined a new macro (what else by cut'n'paste of that single line and blind replacement of EXPORT with IMPORT) for the clients. After you pointed out, changing the typo as follows fixes it:
    Qt Code:
    1. // change the following
    2. #define myWidget_DLL_IMPORT Q_DECL_IMPORT
    3. // to redefining the "real" export macro as
    4. #define myWidget_DLL_EXPORT Q_DECL_IMPORT
    To copy to clipboard, switch view to plain text mode 
    Thanks for your help!

    I guess all the clean pure C++ code that I gained by using CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS variable is gone now. At least for the DLLs that emit signals ...

Similar Threads

  1. Replies: 3
    Last Post: 12th November 2014, 09:38
  2. Replies: 2
    Last Post: 18th April 2013, 13:15
  3. function pointers as parameters in signals and slots
    By ggdev001 in forum Qt Programming
    Replies: 5
    Last Post: 21st February 2013, 23:19
  4. Segmentation fault and lost ui pointer?
    By poporacer in forum Newbie
    Replies: 0
    Last Post: 19th December 2010, 00:42
  5. lost signals ?
    By deepinlife in forum Qt Programming
    Replies: 3
    Last Post: 17th June 2008, 11:11

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.