如何运行需要QT的简单CPP文件

How to run a simple cpp file that requires QT?

本文关键字:QT 简单 CPP 文件 何运行 运行      更新时间:2023-10-16

我在计算机上安装了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定义吗?我真的被困了,我可以使用任何帮助。

谢谢吉尔。

  1. (可选)更新QT 5.2。

  2. 开始QT创建者。

  3. 创建一个新的QT小部件应用程序项目。您可以给类/文件随机名称,没关系。取消选中"生成表单"选项,因为您不需要任何表格。

  4. 从项目中删除Main.CPP以外的所有文件。您可以通过在左侧的项目树中右键单击它们并选择删除文件来做到这一点。

  5. 将代码复制到主CPP中。确保您完全替换了main.cpp的内容,默认内容不应再存在了。

  6. 将OpenCV库添加到项目中。右键单击项目的根部,选择"添加库",然后从那里走。

  7. 通过右键单击项目根并选择" run qmake"。

  8. 来重新运行QMAKE
  9. 通过按CTRL-R(Mac上的CMD-R)来构建并运行项目。

qt使用(非标准)自定义工具链,该工具链必须在可以编译QT依赖的代码之前运行。我从未尝试过在QTCreator之外使用QT,但是如果您真的需要QT,我建议您使用QTCreator IDE。如果您还没有使用它。这是一个非常不错的IDE,即使对于非QT项目。

另外,如果您还没有这样做,请确保已安装QT SDK;单独的标题还不够。QTCreator本身还不够,您需要SDK。如果您不想这样做,我的建议是看Poco。它不是QT的1:1替代品,而是一个非常成熟的框架。