Visual Studio 2010 Qt Link Problem

六月ゝ 毕业季﹏ 提交于 2019-12-21 02:30:56

问题


I spent the weekend trying to figure this out and I'm on the last step. My goal: to get visual studio 2010 and Qt 4.7.3 to work together.

I installed Qt from source, specifying to build with the following configuration:

configure.exe -debug-and-release -opensource -platform win32-msvc2010 -no-webkit -no-phonon -no-phonon-backend -no-script -no-scripttools -no-qt3support -no-multimedia -no-ltcg

After configuration, I ran nmake, no problems.

In my visual studio 2010 solution, I have two projects.

It's complaining that it cannot link the Qt libraries. In the Common properties

AssetIO was originally built using the Qt IDE, and I used the Qt addin within visual studio to import the project. Compiling the project AssetIO works perfectly fine. However, compiling the Short project results in the following linker errors:

Right click on the Short project, select properties. I added AssetIO as a reference. Clicking on the Configuration properties, VC++ Directories, I have the following Include directories added:

Here are the library files I have for the project:

Rather then post more screen-shots, my include directories for the AssetIO project is: C:\qt_source\4.7.3\include

my library directory for the AssetIO project is: C:\qt_source\4.7.3\bin

Here is the simple source code of the project I am trying to get working (my simple test project)

main.cpp
int main(int argc, char* argv[])
{
    AssetIO::LevelLoader a;
    a.dostuff();

    return 0;
}

LevelLoader.h

#ifndef LEVELLOADER_HPP
#define LEVELLOADER_HPP

namespace AssetIO
{
    class LevelLoader {
    public:
        explicit LevelLoader();
        ~LevelLoader();

        void dostuff();
    };
}

#endif // LEVELLOADER_HPP

LevelLoader.cpp

#include "LevelLoader.hpp"
#include <QDomDocument>
#include <QFile>
#include <QDebug>
#include <QString>

using namespace AssetIO;

enum ComponentType { Drawable = 0, Position };

// This will definitely be changed, to return a full-blown component. Passing the tagname directly to the
// component factory.
ComponentType ConvertToComponentType(QString tagName)
{
if(tagName.toLower() == "Drawable") {
    return Drawable;
}
else if(tagName.toLower() == "Position") {
    return Position;
}
else {
    // LOG
    exit(EXIT_FAILURE);
}
}

LevelLoader::LevelLoader()
{
}

LevelLoader::~LevelLoader()
{
}

void LevelLoader::dostuff()
{
QDomDocument doc("la");
QFile file("../../../Resources/input.sto");

if(!file.open(QIODevice::ReadOnly)) {
    // TODO: log this, something
    exit(EXIT_FAILURE);
}

if( !doc.setContent(&file)) {
    // TODO: log
    file.close();
}
// we close the file now the doc has control (i think)
file.close();

// Read the root element
QDomElement root = doc.documentElement();
if(root.tagName() != "Root") {
    // TODO: log
    exit(EXIT_FAILURE);
}

// Read the Header Info
QDomNode headerNode = root.firstChild();

QDomElement e = headerNode.toElement();
if(e.tagName().toLower() != "HeaderInfo") {
    // LOG
}

QDomNodeList componentNode = headerNode.childNodes();
int s = componentNode.count();

QString componentTag(componentNode.at(0).toElement().tagName());
QDomNamedNodeMap a = componentNode.at(0).attributes();
}

I cannot figure out what I am doing incorrectly. Does anyone have any ideas? I have looked everywhere for a solution.


回答1:


Haven't you forgot to specify Qt lib files for VS to link with? You'll probably need QtCored4.lib, QtGuid4.lib (d is for "debug", remove it in release config), and, maybe, some others. If the project that gives you trouble is .exe application - go to it's Properties->Linker->Command Line and add {Qored4.lib QtGuid4.lib} without the brackets.

P. S. My recommendation: first, create a project in Qt Creator and test it. Then run qmake -tp vc -r - and you''l get a perfectly working solution for VS or any other major platform. Besides, Creator has a nice editor, you might like it.




回答2:


I see that your library directories is missing C:\qt_source\4.7.3\lib , include it.

And then include

QtCored4.lib QtGuid4.lib and any other Qt libraries

required as Violet Giraffe suggested. You also need to do this with 'Release version'

QtCore4.lib QtGui4.lib and any other Qt libraries

CV




回答3:


if u have created instance of Qt class QDomDocument. it might be necessary to add "QtXml4.lib" . Please add this lib in Visual studio ie Project->properties->Linker->Input====> Additional Dependencies.



来源:https://stackoverflow.com/questions/7231764/visual-studio-2010-qt-link-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!