Visual Studio 2010 Qt链接问题

Sho*_*ort 5 c++ linker qt visual-studio-2010

我花了整个周末试图解决这个问题,我正在迈出最后一步.我的目标:让visual studio 2010和Qt 4.7.3一起工作.

我从源代码安装了Qt,指定使用以下配置进行构建:

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

配置完成后,我运行nmake,没问题.

在我的visual studio 2010解决方案中,我有两个项目. 图片 它抱怨它无法链接Qt库.在Common属性中

AssetIO最初是使用Qt IDE构建的,我使用visual studio中的Qt插件导入项目.编译项目AssetIO工作得非常好.但是,编译Short项目会导致以下链接器错误: LinkerErrors 右键单击Short项目,选择属性.我添加了AssetIO作为参考.单击配置属性VC++目录,我添加了以下Include目录:

包括目录 以下是我为项目提供的库文件: 图书馆目录 而不是发布更多的屏幕截图,我的AssetIO项目的包含目录是:C:\ qt_source\4.7.3\include

我的AssetIO项目的库目录是:C:\ qt_source\4.7.3\bin

这是我想要工作的项目的简单源代码(我的简单测试项目)

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

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

LevelLoader.h

#ifndef LEVELLOADER_HPP
#define LEVELLOADER_HPP

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

        void dostuff();
    };
}

#endif // LEVELLOADER_HPP
Run Code Online (Sandbox Code Playgroud)

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();
}
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚我做错了什么.有没有人有任何想法?我到处寻找解决方案.

Vio*_*ffe 5

你有没有忘记为VS链接指定Qt lib文件?你可能需要QtCored4.lib,QtGuid4.lib(d代表"debug",在发布配置中删除它),也许还需要其他一些.如果让你麻烦该项目的.exe应用 - 去它的属性 - >连接器 - >命令行,并添加{Qored4.lib QtGuid4.lib}无支架.

PS我的建议:首先,在Qt Creator中创建一个项目并进行测试.然后运行qmake -tp vc -r - 你将获得VS或任何其他主要平台的完美工作解决方案.此外,Creator有一个很好的编辑器,你可能会喜欢它.