Results 1 to 2 of 2

Thread: QtTest: forced to #include .cpp file

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QtTest: forced to #include .cpp file

    The test program needs to be complete, that is, it must have an implementation of OutgoingCall and not just a declaration. The linker cannot find the implementation, i.e. Undefined symbols, and fails to put together a complete program. Your PRO file does not pull that implementation in either as a SOURCES or linked as part of a library. Your #include kludge drags the source of the implementation directly into your test source code, making the implementation available.

    The cleaner way would be adding to SOURCES. If the OutgoingCall class is a QObject then you should also add the header to the HEADERS variable so that moc gets to see it.

    Qt Code:
    1. QT += core testlib
    2. TEMPLATE = app
    3. TARGET = test
    4. INCLUDEPATH += . ..
    5.  
    6. # Input
    7. SOURCES += \
    8. main.cpp \
    9. testoutgoingcall.cpp \
    10. testscopelock.cpp \
    11. ..\OutgoingCall.cpp
    12.  
    13. HEADERS += \
    14. testoutgoingcall.h \
    15. testscopelock.h \
    16. testcase.h \
    17. ..\OutgoingCall.h
    To copy to clipboard, switch view to plain text mode 

    The INCLUDEPATH is only used to find included files that are not literally where the #include says. The INCLUDEPATH ".." entry is necessary if you wish to use:
    Qt Code:
    1. #include "OutgoingCall.h"
    2. // instead of
    3. #include "../OutgoingCall.h"
    To copy to clipboard, switch view to plain text mode 
    in your test code.

  2. The following user says thank you to ChrisW67 for this useful post:

    Urthas (5th August 2015)

Similar Threads

  1. Replies: 2
    Last Post: 21st March 2014, 18:53
  2. QWidget forced the application closed
    By cic in forum Newbie
    Replies: 0
    Last Post: 27th June 2013, 17:41
  3. Replies: 1
    Last Post: 23rd May 2011, 04:53
  4. Replies: 3
    Last Post: 1st November 2010, 16:33
  5. Replies: 4
    Last Post: 9th May 2010, 16:18

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
  •  
Qt is a trademark of The Qt Company.