30 lines
931 B
C++
30 lines
931 B
C++
#include <qfile.h>
|
|
#include <string>
|
|
#define CsvHeadStr "时间,条码,相机名,总结果,撕裂,翻折,极耳宽,极耳高,焊印1,焊印2\r\n"
|
|
#define CRLF "\n"
|
|
std::vector<std::vector<std::string>>tmpSav;
|
|
void WriteToCsv(std::string filePath, std::vector<std::string> strList)
|
|
{
|
|
QFile CsvFile(QString::fromStdString(filePath));
|
|
bool FileExist = CsvFile.exists();
|
|
bool res = CsvFile.open(QIODevice::ReadWrite | QIODevice::Append | QIODevice::Text);
|
|
tmpSav.push_back(strList);
|
|
if (res == true)
|
|
{
|
|
QByteArray byteArray;
|
|
if (FileExist == false)
|
|
{
|
|
byteArray.append(CsvHeadStr);
|
|
}
|
|
for (auto data : tmpSav)
|
|
{
|
|
for (int cnt = 0; cnt < data.size() - 1; cnt++)
|
|
byteArray.append(QByteArray::fromStdString(data[cnt]) + ",");
|
|
byteArray.append(QByteArray::fromStdString(data[data.size() - 1]) + CRLF);
|
|
}
|
|
tmpSav.clear();
|
|
CsvFile.write(byteArray);
|
|
CsvFile.waitForBytesWritten(1);
|
|
CsvFile.close();
|
|
}
|
|
} |