在QT Creator中,我决定在测试所在的位置创建自动测试项目。我的第一步是使我的主要项目子目录,但当我添加子目录模板时,项目不会构建。似乎所有继承自QObject的类现在都是"类";未知类型";。这是我的主要项目.pro文件:
QT += quick
QT += core gui
QT += network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TEMPLATE = subdirs
# the line above breaks project. Whithout it project compiles...
CONFIG += c++11 qml_debug declarative_debug console
win32 {
LIBS += -lws2_32
}
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES +=
applicationservice.cpp
blinkingtimer.cpp
shapes/genericshape.cpp
shapes/circle.cpp
shapes/textprint.cpp
shapes/tracksection.cpp
shapes/triangle.cpp
main.cpp
shapes/square.cpp
shapes/trainsignal.cpp
cliarguments.cpp
guimanager.cpp
desktopgeometry.cpp
tinyxml2/tinyxml2.cpp
RESOURCES += qml.qrc
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
DISTFILES +=
HEADERS +=
applicationservice.h
blinkingtimer.h
customtypes.h
shapes/genericshape.h
shapes/circle.h
shapes/textprint.h
shapes/tracksection.h
shapes/triangle.h
shapes/square.h
shapes/trainsignal.h
cliarguments.h
guimanager.h
desktopgeometry.h
tinyxml2/tinyxml2.h
一个项目不能同时是subdirs
和app
,这就是您在这里尝试的。
最好的方法是将你的主项目移到一个子文件夹中(我在这里称之为"应用程序"(,与你的测试项目("测试"(相同。然后在根文件夹中添加一个总体子目录项目:
文件夹结构:
Rootdir/
|-- RootProject.pro
|-- App/
|-- App.pro
|-- <source files etc>
|-- Tests/
|-- Tests.pro
|-- <source files etc>
RootProject.pro
TEMPLATE = subdirs
SUBDIRS +=
App
Tests