我正在尝试向现有的Qt应用程序添加一些网络功能,为此我有一个工作的MSVC项目文件。我的出发点是Qt安装提供的'fortune server'网络示例。我没有问题在Qt Creator中编译,但在MSVC中失败。为了得到一个有效的MSVC项目,我不得不使用Qt插件并导入Qt Creator .pro文件。这也适用,但我的问题是,我需要修改我现有的Qt项目,以使“财富服务器”示例在其中编译。在详细了解所有项目设置后,我无法找到工作和非工作项目之间的相关区别。在MSVC中配置Qt项目设置
我想缺少的设置必须是什么在.pro文件表示的等效,这是没有太大的:
QT += network widgets
HEADERS = server.h
SOURCES = server.cpp \
main.cpp
# install
target.path = $$[QT_INSTALL_EXAMPLES]/network/fortuneserver
INSTALLS += target
编译器错误,我得到的是基本包含语句失败,如:
#include <QtWidgets>
因为找不到文件/目录。
我可以解决这个问题通过增加一吨的包括语句(从示例修改server.cpp):
#include <QtWidgets/QWidget>
#include <QtNetwork/QtNetwork>
#include <QtWidgets/QLabel>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QHBoxLayout>
#include <QtGui/QGuiApplication>
#include <QtNetwork/QTcpServer>
#include <QtNetwork/QNetworkSession>
#include <QtGui/QStyleHints>
#include <QtWidgets/QGroupBox>
#include <QtWidgets/QMessageBox>
(与工作项目,我并不需要所有类的所有那些明确的夹杂物)
但是,它仍然不能编译,我得到很多的错误线沿线的:
Error 2 error LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl qt_assert(char const *,char const *,int)" ([email protected]@[email protected]) referenced in function "public: class QObjectData * __thiscall QScopedPointer<class QObjectData,struct QScopedPointerDeleter<class QObjectData> >::operator->(void)const " ([email protected]@@[email protected]@@@@@@[email protected]@XZ) c:\Users\xxx\documents\visual studio 2013\Projects\servertest\servertest\moc_server.obj
因为我知道这些代码应该工作,我觉得有ough吨是我微不足道的小事。
感谢
您需要将必要的Qt模块添加到您的项目中。你可以通过Qt插件的项目设置来做到这一点。 –
你使用哪个版本的qt插件?有一个新的VS2015可以正常工作,但被标记为beta版本。基本上,你应该配置插件,以便在项目中使用所需的qt版本,然后插件将负责添加包含目录和库文件。 –