2011-08-29 117 views
5

我花了这个周末试图弄清楚这一点,并且我正走在最后一步。我的目标是:让visual studio 2010和Qt 4.7.3一起工作。Visual Studio 2010 Qt链接问题

我从源Qt安装,以指定要建立具有以下配置:

configure.exe -debug和释放-opensource -platform Win32的msvc2010 -no-webkit的-no声子-no - 声子-backend -no-script -no-scripttools -no-qt3support -no-multimedia -no-ltcg

配置完成后,我跑了nmake,没问题。

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

AssetIO最初是使用Qt IDE构建的,我在Visual Studio中使用了Qt插件来导入项目。编译项目AssetIO工作得很好。但是,编译Short项目会导致以下链接器错误: LinkerErrors 右键单击Short项目,选择属性。我添加了AssetIO作为参考。单击该配置属性,VC++目录,我有以下的包括添加的目录:

Include Directories 这里是库文件,我对项目: Library Directories 而是然后发布更多屏幕截图,我包括目录AssetIO项目是: C:\ qt_source \ 4.7.3 \包括

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

我想不出我在做什么错误。有没有人有任何想法?我到处寻找解决方案。

回答

5

你没有忘记指定VS链接的Qt库文件吗?你可能需要QtCored4.lib,QtGuid4.lib(d是用于“调试”,在发布配置中将其删除),或许还有其他一些。如果给你带来麻烦的项目是.exe应用程序 - 进入它的属性 - >连接器 - >命令行并添加没有括号的{Qored4.lib QtGuid4.lib}。

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

+0

我通过使用命令参数运行qmake来实现它,你的意思是从命令行正确吗?我打算使用Qt作为编辑器,这非常好。我只是想在visual studio 2010中调试exe时能够进入我的assetIO项目。 – Short

4

我看到你的图书馆目录丢失了C:\qt_source\4.7.3\lib,包括它。

然后包括

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

如紫长颈鹿建议需要。您还需要与 '发布版本'

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

CV

1

如果u创建QDomDocumentQt类的实例来做到这一点。可能需要添加“QtXml4.lib”。请在Visual Studio中添加这个库,例如Project->properties->Linker->Input====> Additional Dependencies