2011-08-29 111 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