fulis
fulis

Reputation: 123

Configuring Qt project settings in MSVC

I'm trying to add some network functionality to an existing Qt application, for which I have a working MSVC project file. My starting point for this was the 'fortune server' networking example that is provided with the Qt installation. I have no problem getting this to compile in Qt Creator, but in MSVC it fails. To get a working MSVC project I had to use the Qt plugin and import the Qt Creator .pro file. This also works, but the issue I have is that I need to modify my existing Qt project to make the 'fortune server' example compile within it. After pouring over all the project settings I cannot find where the relevant differences between the working and non-working projects are.

I figure the missing settings have to be the equivalent of what is expressed in the .pro file, which isn't much:

QT += network widgets

HEADERS       = server.h
SOURCES       = server.cpp \
                main.cpp

# install
target.path = $$[QT_INSTALL_EXAMPLES]/network/fortuneserver
INSTALLS += target

The compiler errors I get are basic include statements failing, like:

#include <QtWidgets>

because it can't find the file/directory.

I could fix that by adding a ton of include statements (modified server.cpp from the example):

#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>

(With the working project I don't need all those explicit inclusions of all the classes)

However, it still doesn't compile and I get lots of errors along the lines of:

Error   2   error LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl qt_assert(char const *,char const *,int)" (__imp_?qt_assert@@YAXPBD0H@Z) referenced in function "public: class QObjectData * __thiscall QScopedPointer<class QObjectData,struct QScopedPointerDeleter<class QObjectData> >::operator->(void)const " (??C?$QScopedPointer@VQObjectData@@U?$QScopedPointerDeleter@VQObjectData@@@@@@QBEPAVQObjectData@@XZ)  c:\Users\xxx\documents\visual studio 2013\Projects\servertest\servertest\moc_server.obj 

Since I know that the code should work I feel like there ought to be something trivial I'm missing.

Thanks

Upvotes: 2

Views: 4330

Answers (1)

Xiver
Xiver

Reputation: 71

It sounds like you have not set up the proper include directories, library directories, and library references. There are slight changes between versions of MSVC, but you should be able to track them down by right clicking on the project name and selected properties in the Solution Explorer window. This next part is a bit confusing, because there are multiple places where you can set the following information, I'll try to explain both.

In MSVS 2015 there is a VC++ Directories section in Configuration Properties. I believe this is where you set the paths for the entire solution.

  • Set the Include Directories to include your include path for Qt.
  • Set the Library Directories to include your lib file path for Qt.

This can also be set on a per project basis, from the Solution Explorer.

  • Under C/C++ -> General -> Additional Include Directories
  • Under Linker -> General -> Additional Library Directories

The appropriate lib file(s) will also need to be included.

  • Under Linker -> Input -> Additional Dependencies

OR

  • Add the following code to the appropriate cpp file:

    #pragma comment (lib, "libfile.lib") 
    

I recommend using the per project settings for your include and library paths.

Upvotes: 1

Related Questions