Visual Studio 2010 Qt 链接问题
我花了整个周末试图解决这个问题,现在我已经迈出了最后一步。我的目标:让 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();
}
我无法弄清楚我做错了什么。有人有什么想法吗?我到处寻找解决方案。
I spent the weekend trying to figure this out and I'm on the last step. My goal: to get visual studio 2010 and Qt 4.7.3 to work together.
I installed Qt from source, specifying to build with the following configuration:
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
After configuration, I ran nmake, no problems.
In my visual studio 2010 solution, I have two projects.
It's complaining that it cannot link the Qt libraries. In the Common properties
AssetIO was originally built using the Qt IDE, and I used the Qt addin within visual studio to import the project. Compiling the project AssetIO works perfectly fine. However, compiling the Short project results in the following linker errors:
Right click on the Short project, select properties. I added AssetIO as a reference. Clicking on the Configuration properties, VC++ Directories, I have the following Include directories added:
Here are the library files I have for the project:
Rather then post more screen-shots, my include directories for the AssetIO project is:
C:\qt_source\4.7.3\include
my library directory for the AssetIO project is:
C:\qt_source\4.7.3\bin
Here is the simple source code of the project I am trying to get working (my simple test project)
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();
}
I cannot figure out what I am doing incorrectly. Does anyone have any ideas? I have looked everywhere for a solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你没有忘记指定 VS 链接的 Qt lib 文件吗?您可能需要 QtCored4.lib、QtGuid4.lib(d 表示“调试”,在发布配置中将其删除),也许还需要其他一些。如果给您带来麻烦的项目是 .exe 应用程序 - 转到它的“属性”->“链接器”->“命令行”并添加不带括号的 {Qored4.lib QtGuid4.lib}。
PS我的建议:首先,在Qt Creator中创建一个项目并测试它。然后运行 qmake -tp vc -r - 你将获得适用于 VS 或任何其他主要平台的完美工作解决方案。另外,Creator 有一个不错的编辑器,你可能会喜欢。
Haven't you forgot to specify Qt lib files for VS to link with? You'll probably need QtCored4.lib, QtGuid4.lib (d is for "debug", remove it in release config), and, maybe, some others. If the project that gives you trouble is .exe application - go to it's Properties->Linker->Command Line and add {Qored4.lib QtGuid4.lib} without the brackets.
P. S. My recommendation: first, create a project in Qt Creator and test it. Then run qmake -tp vc -r - and you''l get a perfectly working solution for VS or any other major platform. Besides, Creator has a nice editor, you might like it.
我发现您的库目录缺少
C:\qt_source\4.7.3\lib
,请包含它。然后包括
QtCored4.lib QtGuid4.lib 以及Violet Giraffe 建议所需的 。您还需要使用“发布版本”来执行此操作
CV
I see that your library directories is missing
C:\qt_source\4.7.3\lib
, include it.And then include
required as Violet Giraffe suggested. You also need to do this with 'Release version'
CV
如果您已经创建了
Qt
类QDomDocument
的实例。可能需要添加“QtXml4.lib”。请在 Visual Studio 中添加此库,即Project->properties->Linker->Input====>附加依赖项
。if u have created instance of
Qt
classQDomDocument
. it might be necessary to add "QtXml4.lib" . Please add this lib in Visual studio ieProject->properties->Linker->Input====> Additional Dependencies
.