Moving from Qt4 to Qt5 - linker problem. Explicit instantiations problem or (hopefully) something else?



  • The following compiled, linked and worked with qmake-qt4. With qmake the linker fails with message undefined reference to `void TabScreen::addNewScreen<ScreenA>(ScreenA*, Qt::Orientation)'

    Is this a result of differences between Qt4 and Qt5 which means I will have to change the code or is it something simpler, like my error in moving the code to Qt5? The only difference in project files is the extra line QT+=widgets added to the Qt5.

    tabScreen.h
    @class TabScreen : public QFrame
    {
    public:
    template<class ScreenType>
    void addNewScreen(ScreenType *, Qt::Orientation);
    };
    @

    tabScreen.cpp
    @
    #include "tabScreen.h"
    #include "screenControl.h"

    template<class ScreenType, class NewScreenType>
    void TabScreen::changeScreenLayout(ScreenType * screen, NewScreenType * newScreen, Qt::Orientation orientation)
    {
    // calls Fn from screenControl.h (below)
    ScreenLayoutControl<TabScreen>::addScreen(screen,newScreen,orientation);
    }

    template<class ScreenType>
    void TabScreen::addNewScreen(ScreenType * screen, Qt::Orientation orientation)
    {
    changeScreenLayout(screen, new ScreenChooser(this), orientation);
    }
    @

    screenControl.h
    @
    #include "tabScreen.h"

    template<class ParentType>
    struct ScreenLayoutControl
    {
    template<class ScreenType, class NewScreenType>
    void static addScreen(ScreenType * s1, NewScreenType * s2, Qt::Orientation orientation)
    {
    // do stuff
    }
    // ...
    }

    template<>
    struct ScreenLayoutControl<BaseScreen>
    {
    template<class ScreenType, class NewScreenType>
    void static addScreen(ScreenType * s1, NewScreenType * s2, Qt::Orientation orientation)
    {
    // do stuff
    }
    // ...
    }
    @



  • Never mind, it was explicit instantiations. Problem solved.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.