Results 1 to 6 of 6

Thread: Strange problem of unresolved symbols

  1. #1
    Join Date
    Mar 2010
    Location
    Auckland, NZ
    Posts
    114
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Strange problem of unresolved symbols

    I am stuck on a weird problem. In several Qt programs I use extended versions of QLabel, QCheckBox and QGroupBox. For example here is qmygroupbox.h

    #ifndef QMYGROUPBOX_H
    #define QMYGROUPBOX_H

    #include <qgroupbox.h>
    #include <QMouseEvent>

    class QMyGroupBox: public QGroupBox
    {
    Q_OBJECT
    public:
    QMyGroupBox(QWidget *parent = 0);
    signals:
    void groupBoxClicked(QString text);
    private:
    void mousePressEvent (QMouseEvent *event);
    };

    #endif

    In QtCreator I promote a QGroupBox, for example, to QMyGroupBox. This has been working well for years. Now in one program I am getting link errors:

    mainwindow.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall QMyCheckBox::QMyCheckBox(class QWidget *)" (??0QMyCheckBox@@QAE@PAVQWidget@@@Z) referenced in function "public: void __thiscall Ui_MainWindow::setupUi(class QMainWindow *)" (?setupUi@Ui_MainWindow@@QAEXPAVQMainWindow@@@Z)
    mainwindow.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall QMyGroupBox::QMyGroupBox(class QWidget *)" (??0QMyGroupBox@@QAE@PAVQWidget@@@Z) referenced in function "public: void __thiscall Ui_MainWindow::setupUi(class QMainWindow *)" (?setupUi@Ui_MainWindow@@QAEXPAVQMainWindow@@@Z)
    mainwindow.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall QMyLabel::QMyLabel(class QWidget *)" (??0QMyLabel@@QAE@PAVQWidget@@@Z) referenced in function "public: void __thiscall Ui_MainWindow::setupUi(class QMainWindow *)" (?setupUi@Ui_MainWindow@@QAEXPAVQMainWindow@@@Z)

    I have not been able to what is different about this program. I am using Qt 4.8.6 with MSVC 11.0 (VS 2010). Other programs with the same toolchain, same usage of the promoted widgets build without problems.

    Any suggestions?

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,716
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Strange problem of unresolved symbols

    Promotion in QtCreator is simply a way to tell QtCreator you are using a subclass of a Qt witdget, so that it knows to include the correct header for your widget, that is all.
    Where is the implementation of the header you posted?
    The errors are linking error, which means probably the lib or object files of your custom widgets is not found (have a look a previous errors).
    Make sure the link paths are correctly set to include the lib of your custom widgets (if you are indeed use a lib).
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Mar 2010
    Location
    Auckland, NZ
    Posts
    114
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Strange problem of unresolved symbols

    Quote Originally Posted by high_flyer View Post
    Promotion in QtCreator is simply a way to tell QtCreator you are using a subclass of a Qt witdget, so that it knows to include the correct header for your widget, that is all.
    Where is the implementation of the header you posted?
    The errors are linking error, which means probably the lib or object files of your custom widgets is not found (have a look a previous errors).
    Make sure the link paths are correctly set to include the lib of your custom widgets (if you are indeed use a lib).
    I will undoubtedly reveal my ignorance, but that's OK.

    What is really puzzling is that this is a program that builds without any problems on another machine, the only difference that I can see being that the other machine is using Qt 4.8.1 and MSVC 10, rather than Qt 4.8.6 and MSVC 11. The source code, .ui and pro files are all identical. What's more, on both machines I have several other Qt programs using these same extended classes.

    There are no compile errors.

    I'm puzzled by your question about implementation of the header. All I have ever done to use these custom widgets is make the header files available (I showed qmygroupbox.h, the others look just the same.) There are no .lib or .obj files to be supplied by me, although I see that the MOC has created files like moc_qmygroupbox.cpp and moc_qmygroupbox.obj. Would it help to show the .cpp file?

    Just to be sure, I have checked the link command for another project on the same machine that uses the same custom widgets and builds successfully. The link commands are identical. I'm baffled.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,716
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Strange problem of unresolved symbols

    ... the only difference that I can see being that the other machine is...
    Well, it seems you do not understand that object files and/or a lib is needed for the implementation, so what you see is probably what you are aware of to look for.
    Just because you can't see the difference it doesn't mean its not there.

    On the other machines something else is different which allows on thoese setups for the linker to find the symbols it needs that you do not have on the current machine.

    All I have ever done to use these custom widgets is make the header files available (I showed qmygroupbox.h, the others look just the same.) There are no .lib or .obj files to be supplied by me
    Unless the implementation of your custom widgets is not in the header it self (and judging from the way the header is written it doesn't seem like that is the case) then there HAS to be a *.cpp file where classes from your headers are implemented, unless you are using a library someone else wrote, then you need the library and the headers will be enough.

    although I see that the MOC has created files like moc_qmygroupbox.cpp and moc_qmygroupbox.obj. Would it help to show the .cpp file?
    Not at this point, since the link error show that the constructor of your class can't be found, so that is not even a moc issue (yet).

    Can you post your pro file?
    Maybe we can get some hints from there.
    You also can try to look at the errors at build time, search for errors of not found resources (files, libs etc)
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Mar 2010
    Location
    Auckland, NZ
    Posts
    114
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Strange problem of unresolved symbols

    You are dead right. I found my mistake, which was (as usual) a stupid one. While I had "pulled" all the source files to other machine, which already had an earlier version of the code, I forgot to add to the .pro file the .cpp file with the custom widget implementations - the result of a code reorganisation. Thanks for your patience, sorry for wasting your time.

    Cheers, Gib

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,716
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Strange problem of unresolved symbols

    No problem, glad to have been able to help.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Replies: 5
    Last Post: 26th January 2017, 13:28
  2. [MSVC 2010] Static linking and unresolved external symbols
    By Blood9999 in forum Qt Programming
    Replies: 12
    Last Post: 31st December 2014, 22:12
  3. "Unable to read symbols" Problem
    By weaver4 in forum Newbie
    Replies: 10
    Last Post: 20th December 2012, 23:36
  4. Replies: 7
    Last Post: 21st June 2012, 21:37
  5. Replies: 2
    Last Post: 16th March 2012, 07:55

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.