Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f395388060 | ||
|
|
849143bfe1 |
+23
-12
@@ -1,19 +1,30 @@
|
||||
#include <qfile.h>
|
||||
#include <string>
|
||||
#define CsvHeadStr "时间,条码,相机名,总结果,撕裂,翻折,极耳宽,极耳高,焊印1,焊印2\r\n"
|
||||
#define CRLF "\r\n"
|
||||
void WriteToCsv(std::string filePath,std::vector<std::string> strList)
|
||||
#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();
|
||||
CsvFile.open(QIODevice::ReadWrite);
|
||||
if (FileExist == false)
|
||||
CsvFile.write(CsvHeadStr);
|
||||
|
||||
QByteArray qstr;
|
||||
for (int cnt = 0; cnt <strList.size()-1;cnt++)
|
||||
qstr.append(QByteArray::fromStdString(strList[cnt])+",");
|
||||
qstr.append(QByteArray::fromStdString(strList[strList.size()-1]) + CRLF);
|
||||
CsvFile.write(qstr);
|
||||
CsvFile.close();
|
||||
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();
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user