如何运行需要QT的简单CPP文件
How to run a simple cpp file that requires QT?
我在计算机上安装了QT 5.1.1,但是使用它遇到了一些麻烦。我正在尝试运行以下需要QT的简单程序:
//Playing Video
#include "cv.h"
#include "opencv2objdetectobjdetect.hpp"
#include "opencv2corecore.hpp"
#include "opencv2highguihighgui.hpp"
#include "opencv2features2dfeatures2d.hpp"
#include "opencv2calib3dcalib3d.hpp"
#include "opencv2nonfreenonfree.hpp"
#include "highgui.h"
#include <openbropenbr_plugin.h>
using namespace cv;
static void printTemplate(const br::Template &t)
{
const QPoint firstEye = t.file.get<QPoint>("Affine_0");
const QPoint secondEye = t.file.get<QPoint>("Affine_1");
printf("%s eyes: (%d, %d) (%d, %d)n", qPrintable(t.file.fileName()), firstEye.x(), firstEye.y(), secondEye.x(), secondEye.y());
}
int main(int argc, char *argv[])
{
br::Context::initialize(argc, argv);
// Retrieve classes for enrolling and comparing templates using the FaceRecognition algorithm
QSharedPointer<br::Transform> transform = br::Transform::fromAlgorithm("FaceRecognition");
QSharedPointer<br::Distance> distance = br::Distance::fromAlgorithm("FaceRecognition");
// Initialize templates
br::Template queryA("../data/MEDS/img/S354-01-t10_01.jpg");
br::Template queryB("../data/MEDS/img/S382-08-t10_01.jpg");
br::Template target("../data/MEDS/img/S354-02-t10_01.jpg");
// Enroll templates
queryA >> *transform;
queryB >> *transform;
target >> *transform;
printTemplate(queryA);
printTemplate(queryB);
printTemplate(target);
// Compare templates
float comparisonA = distance->compare(target, queryA);
float comparisonB = distance->compare(target, queryB);
// Scores range from 0 to 1 and represent match probability
printf("Genuine match score: %.3fn", comparisonA);
printf("Impostor match score: %.3fn", comparisonB);
br::Context::finalize();
return 0;
}
它也需要OpenCV 2.4.6.1和OpenBR,但这不是问题。
与QT相关的上述代码中的所有定义(变量和函数)都是未定义的。我试图在QT文件夹中找到相关的H文件并包括它们,但这并没有成功,因为我无法罚款qtcore.h(但是一个名为qtcore的不同文件,其中包含lot's,我现在不喜欢使用)。我尝试在项目属性中添加QT" Include"目录下的"附加目录"下的目录,但这也没有用。我还尝试在"附加库目录"下添加QT" lib"文件夹,但这也不起作用。
基本上,我尝试了我能想到的一切。有人可以解释如何使用这些QT定义吗?我真的被困了,我可以使用任何帮助。
谢谢吉尔。
-
(可选)更新QT 5.2。
-
开始QT创建者。
-
创建一个新的QT小部件应用程序项目。您可以给类/文件随机名称,没关系。取消选中"生成表单"选项,因为您不需要任何表格。
-
从项目中删除Main.CPP以外的所有文件。您可以通过在左侧的项目树中右键单击它们并选择删除文件来做到这一点。
-
将代码复制到主CPP中。确保您完全替换了main.cpp的内容,默认内容不应再存在了。
-
将OpenCV库添加到项目中。右键单击项目的根部,选择"添加库",然后从那里走。
-
通过右键单击项目根并选择" run qmake"。
来重新运行QMAKE 通过按CTRL-R(Mac上的CMD-R)来构建并运行项目。
qt使用(非标准)自定义工具链,该工具链必须在可以编译QT依赖的代码之前运行。我从未尝试过在QTCreator之外使用QT,但是如果您真的需要QT,我建议您使用QTCreator IDE。如果您还没有使用它。这是一个非常不错的IDE,即使对于非QT项目。
另外,如果您还没有这样做,请确保已安装QT SDK;单独的标题还不够。QTCreator本身还不够,您需要SDK。如果您不想这样做,我的建议是看Poco。它不是QT的1:1替代品,而是一个非常成熟的框架。
- 如何设置一个简单的CGAL+Qt程序
- Cmake无法在qt-creater/collect2上编译简单的测试程序:错误:ld
- Qt的新信号/时隙语法问题 - 连接到一个简单的函数
- 通过此指针访问时的成员差异和自身的成员指针(简单的 QT 示例问题)
- 请解释为什么这个简单的C++(Qt)代码如此奇怪
- QT创建者:简单程序未解决的外部符号和外部符号错误
- NAS(使用 qt/linux)- 无法建立简单的音频服务器连接测试
- 在Qt中:我可以输出到“stdout”吗,就像使用qDebug()输出到“stderr”一样简单
- 简单的WebKit2示例与QT
- QT-简单的HTTP服务器
- QT GUI最简单的方法可以从另一堂课访问MainWindow
- QT创建者简单的C 程序来自IDE,但不能从Command LNE运行
- 使用 QT 创建器通过树莓派上的 Wifi 执行简单的终端命令
- 简单的Qt视频流应用程序,只有声音,没有视频(白屏)
- 链接器错误在简单的QT C 应用程序中
- Qt简单的文本编辑器,怎么了?
- Qt - 简单循环的执行正在逐渐减慢
- Qt 5.0.2 简单 qWeb View 上的内存泄漏
- Qt C++简单的应用程序初学者问题
- QT:简单的文本从QLineEdit到QLabel的不同类