编译一个简单的 Qt“Hello World!” Visual Studio 2010 Express 中的应用程序?

发布于 2024-09-05 10:00:59 字数 1414 浏览 3 评论 0原文

我正在尝试构建一个基本的 Qt“Hello, world!” Visual Studio 中的应用程序。

我的 moc 步骤可以正常工作(我认为),但现在我不知道如何修复此链接器错误:

1>moc_mainwindow.obj : error LNK2001: unresolved external symbol "public:
static struct QMetaObject const QMainWindow::staticMetaObject"
(?staticMetaObject@QMainWindow@@2UQMetaObject@@B)

我已经进行了大量搜索,但我不知所措。

这是我的包含目录:

  • i:\Qt\4.6.3\include\QtCore;
  • i:\Qt\4.6.3\include\QtGui;
  • i :\Qt\4.6.3\include;
  • i:\Qt\4.6.3\include\ActiveQt;
  • 释放;
  • .;
  • i:\Qt\4.6.3\mkspecs\win32-msvc2008

以下是我要链接的库:

  • i:\Qt\4.6.3\lib\QtGui4.lib;
  • i:\Qt\4.6.3\lib\QtCore4.lib;
  • gdi32.lib;
  • comdlg32.lib;
  • oleaut32.lib;
  • imm32.lib;
  • winmm.lib;
  • winspool.lib;
  • ws2_32.lib;< /code>
  • ole32.lib;
  • user32.lib;
  • advapi32.lib;
  • libpng.lib;
  • msimg32.lib;
  • shell32.lib;
  • kernel32.lib;
  • uuid.lib;

有人有什么想法吗?

I'm trying to build a basic Qt "Hello, world!" application inside Visual Studio.

I got the moc step to work (I think), but now I am at a loss as to how to fix this linker error:

1>moc_mainwindow.obj : error LNK2001: unresolved external symbol "public:
static struct QMetaObject const QMainWindow::staticMetaObject"
(?staticMetaObject@QMainWindow@@2UQMetaObject@@B)

I've done a lot of searching but I am at a loss.

Here are my include directories:

  • i:\Qt\4.6.3\include\QtCore;
  • i:\Qt\4.6.3\include\QtGui;
  • i:\Qt\4.6.3\include;
  • i:\Qt\4.6.3\include\ActiveQt;
  • reease;
  • .;
  • i:\Qt\4.6.3\mkspecs\win32-msvc2008

Here are the libraries I am linking against:

  • i:\Qt\4.6.3\lib\QtGui4.lib;
  • i:\Qt\4.6.3\lib\QtCore4.lib;
  • gdi32.lib;
  • comdlg32.lib;
  • oleaut32.lib;
  • imm32.lib;
  • winmm.lib;
  • winspool.lib;
  • ws2_32.lib;
  • ole32.lib;
  • user32.lib;
  • advapi32.lib;
  • libpng.lib;
  • msimg32.lib;
  • shell32.lib;
  • kernel32.lib;
  • uuid.lib;

Does anyone have any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

春庭雪 2024-09-12 10:00:59

qmake 将从 .pro 文件中的头文件生成 moc voodoo。由于您没有使用 qmake,从它的声音来看,而是一个本机 Visual Studio 项目,这可能是问题的原因。

如果你使用 qmake 生成你的 Visual Studio 项目,你的所有问题都会消失,生活将变得甜蜜。大概!

我用的是open 2010.05;显然你想用正确的路径替换你的版本。

设置环境

从开始菜单启动 2010 命令环境
-set include=%include%;C:\Qt\2010.05\qt\include
-set lib=%lib%;C:\Qt\2010.05\qt\lib
-设置路径=%path%;C:\Qt\2010.05\qt\bin
-set QMAKESPEC=win32-msvc2010

编写代码、创建文件等

生成初始 pro 和 makefile 并启动 VS
-qmake -tp vc
-qmake

你现在应该有一个 makefile - 通过运行检查它是否有效:
-nmake

现在启动 Visual Studio
-VCExpress.exe /useenv
-XXX.vcxproj 现在可以打开

如果这不起作用,您可能需要针对 Visual Studio 构建 qt。这非常简单 - 转到 qt 目录(从 Visual Studio Express 命令窗口中)并输入:

configure.exe -platform win32-msvc2010 -no-webkit -no-phonon -no-phonon-backend -no-script -no-scripttools -no-multimedia -no-qt3support -fast

qmake will generate the moc voodoo from the header file in .pro file. As you aren't using qmake, by the sound of it, but a native visual studio project, this is probably the cause of the problem.

If you use qmake to generate your visual studio project all your problems will go away and life will be sweet. Probably!

I am using the open 2010.05; obviously you want to substitute the correct path for your version.

set up the environment

start 2010 command environment from the start menu
-set include=%include%;C:\Qt\2010.05\qt\include
-set lib=%lib%;C:\Qt\2010.05\qt\lib
-set path=%path%;C:\Qt\2010.05\qt\bin
-set QMAKESPEC=win32-msvc2010

write code, create files etc

generate the initial pro and makefile and fire up VS
-qmake -tp vc
-qmake

you should now have a makefile - check that it works by running:
-nmake

now launch visual studio
-VCExpress.exe /useenv
-XXX.vcxproj can now be opened

If this doesn't work you may need to build qt at against visual studio. This is very straightforward - go to the qt directory (from within the visual studio express command window) and type:

configure.exe -platform win32-msvc2010 -no-webkit -no-phonon -no-phonon-backend -no-script -no-scripttools -no-multimedia -no-qt3support -fast
旧城烟雨 2024-09-12 10:00:59

您无法在 VC++ Express 版本上安装 Qt VS 插件。假设您已经编译了 moc,您还需要确保在链接时包含适当的库(*.lib 文件)。这位于“项目属性”>“项目属性”下链接器>输入>附加依赖项。

您至少需要 qtcore4.lib。

另请确保 Qt 库路径位于您的库搜索路径中。在我的计算机上,它是 c:\qt\4.6.2\lib。

You cannot install the Qt VS plugin on the Express edition of VC++. Assuming you got the moc to compile, you also need to make sure you're including the appropriate libraries (*.lib files) at link time. This goes under Project properties > Linker > Input > Additional Dependencies.

You will need qtcore4.lib at a minimum.

Also make sure the Qt library path is in your library search path. On my computer it's c:\qt\4.6.2\lib.

月朦胧 2024-09-12 10:00:59

我能够使用 http://rajorshi.net/blog/2009/01/using-qt-with-msvc-express-2008/http://portfolio.delinkx.com/files/Qt.pdf 作为指南。以防万一有人仍然遇到问题。

I was able to get QT to work with Visual C++ Express 2010 using http://rajorshi.net/blog/2009/01/using-qt-with-msvc-express-2008/ and http://portfolio.delinkx.com/files/Qt.pdf as guides. Just in case anyone still is having problems.

久而酒知 2024-09-12 10:00:59

您是否先使用 qmake 创建了 Visual Studio 项目?问题似乎出在 moc 编译上。你是否安装了qt插件以及环境变量中的qt路径?您可以添加您的 hello world 代码以便我看一下吗?

Have you create the visual studio project using qmake first? The problem seems to be the moc compilation. Do you have qt plug-in installed and the qt path in enviromental variables? Can you add you hello world code so I can have a look at it?

清风疏影 2024-09-12 10:00:59

您需要添加命令来生成 QT 元类,然后还将生成的文件作为 C++ 代码包含在您的项目中。

生成 QT 元类:

  • 首先,将 QT bin 路径添加到可执行目录中。 (这位于“配置属性”>“VC++ 目录”中)

  • 将包含 Q_OBJECT 宏的头文件添加到项目中。

  • 多选您的头文件,然后右键单击头文件,单击“属性”。

    • 将“项目类型”从“C/C++ 标头”更改为“自定义构建工具”。
    • 将命令行设置为:moc.exe "%(FullPath)" > “$(ProjectDir)MetaObjects\moc_%(文件名).cpp”
    • 将描述设置为:QT:生成 $(ProjectDir)MetaObjects\moc_%(Filename).cpp(可选)
    • 将输出设置为:$(ProjectDir)MetaObjects\moc_%(Filename).cpp
  • 运行 Build 只是为了使其生成元对象代码
  • 将生成的 C++ 文件从项目目录 Metaobjects 文件夹添加到您的项目中

You need to add commands to generate QT metaclasses, then also include the generated files in your project as c++ code.

Generating the QT metaclasses:

  • First, add your QT bin path into the Executable Directory. (This is in Configuration Properties > VC++ Directories)

  • Add your Header files that contain Q_OBJECT macros to the project.

  • Multi-select your header files, then right click on a header file, click Properties.

    • Change "Item Type" from "C/C++ Header" to "Custom Build Tool".
    • Set Command line to this: moc.exe "%(FullPath)" > "$(ProjectDir)MetaObjects\moc_%(Filename).cpp"
    • Set Description to this: QT: Generate $(ProjectDir)MetaObjects\moc_%(Filename).cpp (optional)
    • Set Outputs to this: $(ProjectDir)MetaObjects\moc_%(Filename).cpp
  • Run Build just to make it generate the metaobject code
  • Add the generated C++ files from the Project Directory Metaobjects folder into your project
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文