Results 1 to 7 of 7

Thread: Problem building application with custom widget

  1. #1
    Join Date
    Jan 2009
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Problem building application with custom widget

    Hey all, I have a problem building my application when using a custom widget.
    I'm using the custom widget "tictactoe" that came with the examples.

    For creating the project files I used the following steps:
    • cd C:\Qt\4.4.2\projects\Test\Test
    • qmake -project
    • qmake -tp vc test.pro
    • Added "C:\Qt\4.4.2\examples\designer\taskmenuextensi on" to the project include list in visual studio.



    I'm getting the following link error when building my project:

    Error 1 error LNK2019: unresolved external symbol "public: __thiscall TicTacToe::TicTacToe(class QWidget *)" (??0TicTacToe@@QAE@PAVQWidget@@@Z) referenced in function "public: void __thiscall Ui_MyTest::setupUi(class QMainWindow *)" (?setupUi@Ui_MyTest@@QAEXPAVQMainWindow@@@Z) mytest.obj

    Error 2 fatal error LNK1120: 1 unresolved externals debug\test.exe

    Qt Code:
    1. //main.cpp
    2. #include <QApplication>
    3. #include "mytest.h"
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication app(argc, argv);
    8. MyTest mytest;
    9. mytest.show();
    10. return app.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. //mytest.cpp
    2. #include <QtGui>
    3. #include "mytest.h"
    4.  
    5. MyTest::MyTest(QMainWindow *p_Parent) : QMainWindow(p_Parent)
    6. {
    7. setupUi(this);
    8. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. //mytest.h
    2. #ifndef MYTEST_H
    3. #define MYTEST_H
    4.  
    5. #include "ui_mytest.h"
    6.  
    7. class MyTest : public QMainWindow, private Ui::MyTest
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. MyTest(QMainWindow *p_parent = 0);
    13.  
    14. };
    15.  
    16. #endif
    To copy to clipboard, switch view to plain text mode 

    I only get this error when I use a custom widget. Because when I remove the custom widget from my ui file I can successfully build and run the application.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem building application with custom widget

    You have to link with the library providing the custom widget which is either the plugin itself (as is probably the case of the mentioned Qt example) or some other library the plugin links against. A third option is to copy the sources of the needed class to your project.

  3. #3
    Join Date
    Jan 2009
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem building application with custom widget

    Thanks for the fast response wysota.
    But could you give me a bit more detailed information?

    I have tried to link it with the library by adding taskmenuextension.lib and taskmenuextensiond.lib to my visual studio project file. I was not sure which lib was for tictactoe so I included them both to be sure.

    It could be I added the lib file not correct to my project but I'm still getting the same error.
    I'm using visual studio 2005 and added the lib files like this:
    Properties > Configuration properties > Linker > Input > Additional Dependencies

    About the third option. The source was already available for my project because I added C:\Qt\4.4.2\examples\designer\taskmenuextension to the include list.
    In this location are the source files for tictactoe. To be sure I removed this from the include list and copied the source to my project directory. After this I'm still getting the error

    Have you more ideas or didn't I add the library correct in visual studio?
    Or is it possible to add the lib file directly to my *.pro file


    --edit--
    I have added the library now in my pro file by using, LIBS += -l and LIBS += -L.
    After this I runned qmake -tp vc test.pro again.
    When I look now in my project settings in visual studio I see the library is added but when I build my project I still get the same error. Any idea's?
    Last edited by Uthar; 18th January 2009 at 15:03.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem building application with custom widget

    Maybe the plugin doesn't export the class? Try copying the source files into your project directly.

  5. #5
    Join Date
    Jan 2009
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem building application with custom widget

    About the third option. The source was already available for my project because I added C:\Qt\4.4.2\examples\designer\taskmenuextension to the include list.
    In this location are the source files for tictactoe. To be sure I removed this from the include list and copied the source to my project directory. After this I'm still getting the error.
    Tried it already to copy the source to my project directory, unfortunately this didn't solve my problem

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem building application with custom widget

    Did you add them to the project?

  7. The following user says thank you to wysota for this useful post:

    Uthar (19th January 2009)

  8. #7
    Join Date
    Jan 2009
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem building application with custom widget

    Thanks wysota!
    That was the part I was missing. It's working now

    Greetings Uthar

Similar Threads

  1. Problem reimplementing QSpinBox in a custom widget
    By hvengel in forum Qt Programming
    Replies: 1
    Last Post: 30th March 2006, 08:12
  2. Replies: 4
    Last Post: 24th March 2006, 22:50
  3. Problem with custom widget
    By jnana in forum Qt Programming
    Replies: 3
    Last Post: 15th March 2006, 11:55
  4. Replies: 16
    Last Post: 7th March 2006, 15:57
  5. Replies: 4
    Last Post: 1st March 2006, 23:11

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.