【发布时间】:2017-05-02 02:17:31
【问题描述】:
所以我在 Visual Studio 中编写了一些类(它们在 VS 中工作)并将它们添加到 Qt。当我指向一个类时,一切都很好。但是,如果我上课,我会收到关于 2 个方法的 2 个“未解析的外部符号”错误(类中只有 2 个)。其中一个看起来像这样:
mainwindow.obj:-1: error: LNK2001: unresolved external symbol "protected: virtual void __cdecl SRT::processInputLine(class Subtitles &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?processInputLine@SRT@@MEAAXAEAVSubtitles@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
这里是这个方法的声明:
virtual void processInputLine(Subtitles& subtitles, const string& line) throw(TimesOverlap) override;
Class Subtitles 继承向量,其中 Subtitle 是另一个类。
如果我将定义粘贴到这个文件中(我知道我不应该这样做),我只会得到这些方法使用的其他类的相同错误,而不是前 2 个错误。 Qt 没有正确链接 .cpp 文件吗?为什么这个链接错误只有在我创建类时才会发生,而不是之前?有任何想法吗?谢谢!
Edit1:这是我的 .pro 文件:
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += main.cpp\
mainwindow.cpp \
Subtitles.cpp \
MicroDVD.cpp \
MPlayer.cpp \
Subtitle.cpp \
TimeStamp.cpp \
SRT.cpp \
SubtitleIO.cpp
HEADERS += mainwindow.h \
globalVariables.h \
Exceptions.h \
MicroDVD.h \
MPlayer.h \
Subtitle.h \
Subtitles.h \
TimeStamp.h \
SRT.h \
SubtitleIO.h
FORMS += mainwindow.ui
DISTFILES += \
SubtitleEditor.pro.user
如您所见,包含 .h 和 .c 文件。我正在尝试弄清楚如何运行 qmake...
【问题讨论】: