Visual Studio 2010 Qt 链接问题

5
我花了整个周末去尝试解决这个问题,现在只剩最后一步了。我的目标是让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库。在“常规”属性中:
AssetIO最初是使用Qt IDE构建的,并且我使用Visual Studio中的Qt插件导入了该项目。编译AssetIO项目可以完美地工作。但是,编译Short项目会导致以下链接器错误:
单击Short项目,选择属性。我将AssetIO添加为引用。在“配置属性”,“VC++目录”中单击,“包含目录”下添加以下目录:
这是我为项目拥有的库文件:
与其再发布更多截图,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;
}

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();
}

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

3个回答

5
你是否忘记为VS指定Qt库文件以进行链接?你可能需要QtCored4.lib,QtGuid4.lib(d代表“debug”,在发布配置中删除它),以及其他一些库文件。如果出现问题的项目是.exe应用程序,则转到其属性->链接器->命令行,并添加{Qored4.lib QtGuid4.lib}(不包括括号)。
附注:我的建议是:首先在Qt Creator中创建一个项目并进行测试。然后运行qmake -tp vc -r,你将得到一个完美运行于VS或任何其他主要平台的解决方案。此外,Creator还有一个很好的编辑器,你可能会喜欢它。

我通过在命令行中运行qmake命令参数来使其工作,你的意思是这样对吗?我计划使用Qt作为编辑器,它非常好用。我只是想在使用Visual Studio 2010调试exe时能够进入我的assetIO项目。 - Short

4
我发现你的库目录缺少C:\qt_source\4.7.3\lib,请添加它。
接着,按Violet Giraffe建议的方式包含QtCored4.lib、QtGuid4.lib和任何其他需要的Qt库。你也需要在“发布版本”中进行此操作。
同样地,也需要包含QtCore4.lib、QtGui4.lib和任何其他需要的Qt库。
CV

1

如果您已经创建了QtQDomDocument的实例,可能需要添加"QtXml4.lib"。请在Visual Studio中添加此库,即项目->属性->链接器->输入====>附加依赖项


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接