使用现有的 C++代码在 Google Test 下测试并添加 Qt
我正在开发一个用 C++ 编写的程序,使用 Linux (Ubuntu) 中的一些 c++0x 功能。我在 Google Test 中编写了一堆测试。我正在使用 g++ 和生成依赖项的普通 makefile。
现在我想开发一个完全独立的用户界面。
我认为 Qt 会很好,但发现它构建起来有点复杂。我发现最简单的方法是使用 qmake。
我想知道如何将 Qt 构建到我的应用程序中,同时保持所有底层类独立于 Qt。我知道如何通过编写好的代码来做到这一点,但我想要一个好的构建系统。
我不想改用 Qt 的单元测试框架,因为我只想将 Qt 用于 UI,并且我看不到重写测试的意义。
我应该使用 qmake 并修改它来生成我的 google 测试运行程序以及 Qt 应用程序吗? 我是否应该保留我的 makefile 并使用 qmake 仅构建和链接代码的 UI 部分,这将取决于原始 makefile 中生成的 .o 文件? 我应该做点别的吗?
最后,我将如何执行上述选项?
I am working on a program written in C++ using some c++0x features in Linux (Ubuntu). I have written a bunch of tests in Google Test. I am using g++ and plain makefiles which generate dependencies.
Now I want to work on a completely separate UI.
I have decided that Qt will be good, but found that it is kind of complicated to build. I see that the easiest thing is to use qmake.
I was wondering how I can build Qt into my application while keeping all the underlying classes independent of Qt. I understand how to do that by writing good code, but I want a good build system.
I don't want to switch to using Qt's unit testing framework because I only want to use Qt for the UI and I don't see the point of rewriting my tests.
Should I use qmake and modify it to produce my google test runner as well as the Qt app?
Should I keep my makefile and use qmake to build and link only the UI parts of the code which will depend on the .o files produced in the original makefile?
Should I do something else?
Finally, how would I do any of those above options?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
CMake 似乎与 Qt 配合得很好(根据我当前项目的经验)。有一组很好的宏可以完成所有标准的 Qt 事情,而且它与其他工具集成得相当好。您最初的项目可能设置起来有点混乱,但我确信网上有大量的 Qt 示例。
您不需要切换测试框架来使用 CMake。我使用 boost 测试框架,但就 CMake 而言,任何使用返回码的程序都可以正常工作。
如果您使用 cmake,则没有理由部分使用 qmake。
如果这是一个问题的话,Cmake 也是跨平台的。
顺便说一句,您也没有理由必须停止使用 makefile。 Qt 的 qmake 只是调用一堆命令行工具,您也可以在 make 中执行这些工具。
CMake seems to work well with Qt (based on my experiences with my current project). There are a good set of macros to do all the standard Qt things, plus it integrates reasonably well with other tools. Your initial project may be a bit confusing to setup, but I'm sure there are numerous Qt examples available on the net.
You should not need to switch your testing framework to use CMake. I use the boost test framework, but as far as CMake is concerned any program which uses return codes will work just fine.
There is no reason to even partially use qmake if you use cmake.
Cmake is also cross-platform if that is a concern.
BTW, there is also no reason you have to stop using makefiles. Qt's qmake just calls a bunch of command-line tools which you can also do in make.