Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem linking when inheriting from QMainWindow
Forum Updated to NodeBB v4.3 + New Features

Problem linking when inheriting from QMainWindow

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    primem0ver
    wrote on last edited by
    #1

    I am borrowing the "fancymainwindow" class from qtcreator because I like the "manhattan style" and plan on improvising it for my project. The manhattan style refers to this object and I may decide to use it for my main window in the long run anyway.

    However, the fancymainwindow code will not link properly. The only thing I changed at first was the "EXPORT" definition and its include. As is (as the code is) I get 5 missing functions which ARE defined.

    Here are the linking errors:
    @
    error LNK2019: unresolved external symbol "public: __thiscall AppCore::FancyMainWindow::FancyMainWindow(class QWidget *)" (??0FancyMainWindow@AppCore@@QAE@PAVQWidget@@@Z) referenced in function "public: void __thiscall AppCore::FancyMainWindow::`default constructor closure'(void)" (??_FFancyMainWindow@AppCore@@QAEXXZ) D:\Developing\Projects\IMT\Rosweld\trunk\Source\App\AppCore\manhattanstyle.obj AppCore
    error LNK2001: unresolved external symbol "public: __thiscall AppCore::FancyMainWindow::FancyMainWindow(class QWidget *)" (??0FancyMainWindow@AppCore@@QAE@PAVQWidget@@@Z) D:\Developing\Projects\IMT\Rosweld\trunk\Source\App\AppCore\moc_fancymainwindow.obj AppCore
    error LNK2019: unresolved external symbol "public: void __thiscall AppCore::FancyMainWindow::setDockActionsVisible(bool)" (?setDockActionsVisible@FancyMainWindow@AppCore@@QAEX_N@Z) referenced in function "private: static void __cdecl AppCore::FancyMainWindow::qt_static_metacall(class QObject *,enum QMetaObject::Call,int,void * *)" (?qt_static_metacall@FancyMainWindow@AppCore@@CAXPAVQObject@@W4Call@QMetaObject@@HPAPAX@Z) D:\Developing\Projects\IMT\Rosweld\trunk\Source\App\AppCore\moc_fancymainwindow.obj AppCore
    error LNK2019: unresolved external symbol "private: void __thiscall AppCore::FancyMainWindow::onDockActionTriggered(void)" (?onDockActionTriggered@FancyMainWindow@AppCore@@AAEXXZ) referenced in function "private: static void __cdecl AppCore::FancyMainWindow::qt_static_metacall(class QObject *,enum QMetaObject::Call,int,void * *)" (?qt_static_metacall@FancyMainWindow@AppCore@@CAXPAVQObject@@W4Call@QMetaObject@@HPAPAX@Z) D:\Developing\Projects\IMT\Rosweld\trunk\Source\App\AppCore\moc_fancymainwindow.obj AppCore
    error LNK2019: unresolved external symbol "private: void __thiscall AppCore::FancyMainWindow::onDockVisibilityChange(bool)" (?onDockVisibilityChange@FancyMainWindow@AppCore@@AAEX_N@Z) referenced in function "private: static void __cdecl AppCore::FancyMainWindow::qt_static_metacall(class QObject *,enum QMetaObject::Call,int,void * *)" (?qt_static_metacall@FancyMainWindow@AppCore@@CAXPAVQObject@@W4Call@QMetaObject@@HPAPAX@Z) D:\Developing\Projects\IMT\Rosweld\trunk\Source\App\AppCore\moc_fancymainwindow.obj AppCore

    @

    Interestingly there is this inclusion at the end of the fancymainwindow.cpp file:

    @
    #include "fancymainwindow.moc"
    @

    The compiler cannot find this file. If I change the above line to include "moc_fancymainwindow.cpp" I only get two link errors:

    @
    Error 1 error LNK2019: unresolved external symbol "public: __thiscall AppCore::FancyMainWindow::FancyMainWindow(class QWidget *)" (??0FancyMainWindow@AppCore@@QAE@PAVQWidget@@@Z) referenced in function "public: void __thiscall AppCore::FancyMainWindow::`default constructor closure'(void)" (??_FFancyMainWindow@AppCore@@QAEXXZ) D:\Developing\Projects\IMT\Rosweld\trunk\Source\App\AppCore\manhattanstyle.obj AppCore
    Error 2 error LNK2001: unresolved external symbol "public: static struct QMetaObject const AppCore::FancyMainWindow::staticMetaObject" (?staticMetaObject@FancyMainWindow@AppCore@@2UQMetaObject@@B) D:\Developing\Projects\IMT\Rosweld\trunk\Source\App\AppCore\manhattanstyle.obj AppCore
    @

    I can't get rid of these no matter what I try. The class IS exported so that isn't the issue. In addition, both of the functions ARE defined (the latter in the moc file). The Manhattan style code is in the same dll as the fancymainwindow class.

    @
    //from fancymainwindow.cpp
    FancyMainWindow::FancyMainWindow(QWidget *parent) :
    QMainWindow(parent), d(new FancyMainWindowPrivate)
    {
    connect(&d->m_resetLayoutAction, SIGNAL(triggered()),
    this, SIGNAL(resetLayout()));
    }

    // from moc_fancymainwindow.cpp
    const QMetaObject AppCore::FancyMainWindow::staticMetaObject = {
    { &QMainWindow::staticMetaObject, qt_meta_stringdata_AppCore__FancyMainWindow.data,
    qt_meta_data_AppCore__FancyMainWindow, qt_static_metacall, 0, 0}
    };
    @

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      did you modify FancyMainWindow.h ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • P Offline
        P Offline
        primem0ver
        wrote on last edited by
        #3

        Before getting the above issues I only modified the included header that specifies the export (and the export declaration) to "appcore_global.h" and APPCORE_EXPORT within fancymainwindow.h. I didn't even change the namespace until after I had run into the issue and realized it wouldn't matter.

        I later modified the header after the fact because I simplified the way the extraneous classes were organized to try and solve the problem. In my experience sometimes visual studio doesn't like the way that Qt declares namespaces... or perhaps I just don't know when to include bracketed namespaces in the cpp file versus using the @using namepace whatever;@ command. But those changes were an attempt to fix the issue and were only done after the problems above existed.

        1 Reply Last reply
        0
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          I recommend you try to get it to work with the unmodified code, before you tinker with the export declaration and namespaces.

          Also worth trying:

          • Try to get it to work in a standalone app first, before building a DLL.
          • Try the "latest version":https://qt.gitorious.org/qt-creator/qt-creator/source/src/libs/utils/fancymainwindow.cpp of the code, which doesn't have the #include "fancymainwindow.moc" line

          Finally, how did you define APPCORE_EXPORT?

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0
          • P Offline
            P Offline
            primem0ver
            wrote on last edited by
            #5

            If by "work" you mean build I already have. I built the original dll that contains the fancymainwindow inside of QtCreator just to see if I got the same error. No problems linking there. I don't think I need to build other units because as I said (so far), all of the functionality is my version is in the same dll just like it is in QtCreator.

            bq.
            Try the latest version [qt.gitorious.org] of the code, which doesn’t have the #include “fancymainwindow.moc” line

            Hmmm. Interesting. I JUST downloaded the creator source code a few days ago. Perhaps I will but I am surprised one has already been released.

            APPCORE_EXPORT was defined by the new qt project wizard like this:

            @#define APPCORE_EXPORT Q_DECL_EXPORT@

            I will try a standalone app if and when it becomes necessary. Currently I am just using a workaround (by removing the reference to the class from Manhattan Style) since the class is only referenced during a check to make sure the styler doesn't style anything inherited by this class and none of my classes currently inherit from fancymainwindow. I may decide to do so in the future if I find it beneficial.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved