开发者

Visual Studio 2010 Qt Link Problem

开发者_Go百科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.

Visual Studio 2010 Qt Link Problem

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:

Visual Studio 2010 Qt Link Problem

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:

Visual Studio 2010 Qt Link Problem

Here are the library files I have for the project:

Visual Studio 2010 Qt Link Problem

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.


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.


I see that your library directories is missing C:\qt_source\4.7.3\lib , include it.

And then include

QtCored4.lib QtGuid4.lib and any other Qt libraries

required as Violet Giraffe suggested. You also need to do this with 'Release version'

QtCore4.lib QtGui4.lib and any other Qt libraries

CV


if u have created instance of Qt class QDomDocument. it might be necessary to add "QtXml4.lib" . Please add this lib in Visual studio ie Project->properties->Linker->Input====> Additional Dependencies.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜