Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/152.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Visual Studio 2010 Qt链接问题_C++_Visual Studio 2010_Qt_Linker - Fatal编程技术网

C++ Visual Studio 2010 Qt链接问题

C++ Visual Studio 2010 Qt链接问题,c++,visual-studio-2010,qt,linker,C++,Visual Studio 2010,Qt,Linker,我花了一个周末的时间想弄明白这一点,我已经走到了最后一步。我的目标是:让VisualStudio2010和Qt4.7.3协同工作 我从源代码处安装了Qt,并指定使用以下配置生成: configure.exe-调试和发布-开源-平台win32-msvc2010-无webkit-无声子-无声子后端-无脚本-无脚本工具-无QT3支持-无多媒体-无ltcg 配置之后,我运行了nmake,没有问题 在我的VisualStudio2010解决方案中,我有两个项目。 它抱怨它不能链接Qt库。在公共属性中 As

我花了一个周末的时间想弄明白这一点,我已经走到了最后一步。我的目标是:让VisualStudio2010和Qt4.7.3协同工作

我从源代码处安装了Qt,并指定使用以下配置生成:

configure.exe-调试和发布-开源-平台win32-msvc2010-无webkit-无声子-无声子后端-无脚本-无脚本工具-无QT3支持-无多媒体-无ltcg

配置之后,我运行了nmake,没有问题

在我的VisualStudio2010解决方案中,我有两个项目。 它抱怨它不能链接Qt库。在公共属性中

AssetIO最初是使用Qt IDE构建的,我在VisualStudio中使用Qt插件导入项目。编制项目评估工作做得非常好。但是,编译短项目会导致以下链接器错误: 在短项目上单击鼠标右键,选择“属性”。我添加了AssetIO作为参考。单击配置属性、VC++目录,我添加了以下包含目录:

以下是我为该项目准备的库文件: 与发布更多屏幕截图不同,我的AssetIO项目的include目录是: C:\qt\u source\4.7.3\include

AssetIO项目的我的库目录是: C:\qt\u source\4.7.3\bin

下面是我正在努力工作的项目(我的简单测试项目)的简单源代码

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();
}
#包括“LevelLoader.hpp”
#包括
#包括
#包括
#包括
使用名称空间资产;
枚举组件类型{Drawable=0,位置};
//这肯定会改变,返回一个完整的组件。将标记名直接传递给
//组件工厂。
ComponentType ConvertToComponentType(QString标记名)
{
如果(标记名.toLower()=“可绘制”){
回拉;
}
else if(标记名.toLower()=“位置”){
返回位置;
}
否则{
//日志
退出(退出失败);
}
}
LevelLoader::LevelLoader()
{
}
LevelLoader::~LevelLoader()
{
}
void LevelLoader::dostuff()
{
QDOM文件文件(“la”);
QFile文件(“../../../Resources/input.sto”);
如果(!file.open(QIODevice::ReadOnly)){
//TODO:记下这个,什么的
退出(退出失败);
}
如果(!doc.setContent(&file)){
//TODO:日志
file.close();
}
//我们现在关闭文件,文档已经控制了(我想)
file.close();
//读取根元素
QdomeElement root=doc.documentElement();
if(root.tagName()!=“root”){
//TODO:日志
退出(退出失败);
}
//阅读标题信息
QDomNode headerNode=root.firstChild();
QdomeElement e=headerNode.toElement();
如果(e.tagName().toLower()!=“HeaderInfo”){
//日志
}
QDomNodeList componentNode=headerNode.childNodes();
int s=componentNode.count();
QString componentTag(componentNode.at(0.toElement().tagName());
QDomNamedNodeMap a=componentNode.at(0.attributes();
}

我不知道我做错了什么。有人有什么想法吗?我到处都在寻找解决方案。

难道你没有忘记为VS指定要链接的Qt lib文件吗?您可能需要QtCored4.lib、QtGuid4.lib(d代表“debug”,请在发布配置中删除它),还可能需要其他一些。如果给您带来麻烦的项目是.exe应用程序,请转到它的属性->链接器->命令行并添加不带括号的{Qored4.lib QtGuid4.lib}


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

我发现您的库目录缺少
C:\qt\u source\4.7.3\lib
,包括它

然后包括

QtCored4.lib QtGuid4.lib和任何其他Qt库

紫罗兰长颈鹿建议的要求。您还需要使用“发布版本”来执行此操作

QtCore4.lib QtGui4.lib和任何其他Qt库


CV

如果您创建了
Qt
QDomDocument
的实例。可能需要添加“qtml4.lib”。请在Visual studio ie
项目->属性->链接器->输入==>其他依赖项中添加此库

通过使用命令参数运行qmake,我使它工作了,你的意思是从命令行正确吗?我计划使用Qt作为编辑器,它非常好。当我在VisualStudio2010中调试exe时,我只是想能够进入我的assetIO项目。
#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();
}