如何在qt creator中使用此代码 [英] How can I use this code in qt creator

查看:109
本文介绍了如何在qt creator中使用此代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我是使用qt的新手,我想使用这段代码:从Linux上的Flir JPEG中提取RAW图像 [ ^ ]

来制作一个使用Qtcreator的GUI,但我没有成功。



我尝试过:



Hello,

I'm new in using qt and i would like to use this code : Extracting RAW Images from Flir JPEG on Linux[^]
to make a GUI with Qtcreator but i don't succed.

What I have tried:

I'm at the begining and I don't know how to do, I have just put it in Qt creator : 
#include <iostream>
#include <QProcess>
#include <QDebug>
#include <QJsonDocument>
#include <QJsonArray>
#include <QJsonObject>
#include <QFile>

int main(int argc, char** argv)
{
    QString filepath(argv[1]);

    QProcess exiftoolProcess;
    exiftoolProcess.start("exiftool", QStringList() << "-j" << "-b" << filepath);
    if(!exiftoolProcess.waitForFinished(100000))
    {
        qInfo() << "exiftool timed out";
    }

    QByteArray data = exiftoolProcess.readAllStandardOutput();
    QJsonDocument exiftoolDoc = QJsonDocument::fromJson(data);

    QJsonArray dataArray = exiftoolDoc.array();

    QJsonValue value = dataArray[0];

    QJsonObject obj = value.toObject();

    qInfo() << obj.keys();

    int width = obj["RawThermalImageWidth"].toDouble();
    int height = obj["RawThermalImageHeight"].toDouble();

    qInfo() << "Resolution: " << width << "x" << height;

    QString imgBase64Str = obj["RawThermalImage"].toString();
    imgBase64Str.remove(0,7);

    QByteArray image = QByteArray::fromBase64(imgBase64Str.toLocal8Bit());

    qInfo() << image.size();

    QFile file("./output.tif");
    file.open(QIODevice::WriteOnly);
    file.write(image);
    file.close();
}

推荐答案

创建一个新项目(文件 - 新项目)并选择项目类型。对于代码段中的控制台应用程序,请选择其他项目,然后选择 Qt控制台 Plain C ++ ,这是所示代码的类型。然后将文章中的代码粘贴到创建的 main 函数的主体中。



此步骤是创建Qt项目文件所必需的i> qmake.pro ,其中包含构建定义。



如果要创建Qt GUI应用程序,首先要了解它们。从教程|开始Qt Creator手册 [ ^ ]。根据您的要求创建GUI(例如,通过提供选择输入和输出文件的控件)并插入文章中的代码以执行转换。



注意该代码需要安装 exiftool
Create a new project (File - New Project) and select the project type. For console applications like in the code snippet select Other Project and then choose Qt Console or Plain C++ which is the type of the shown code. Then paste the code from the article into the body of the created main function.

This step is necessary to create the Qt project file qmake.pro which contains the build definitions.

If you want to create a Qt GUI application you have first to learn about those. Start at Tutorials | Qt Creator Manual[^]. Create the GUI according to your requirements (here for example by providing controls to select input and output files) and insert the code from the article to perform the conversion.

Note that the code requires the exiftool to be installed.


这篇关于如何在qt creator中使用此代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆