txt转sqlite时,若列值超过最大列数则截断

This commit is contained in:
一二三 2023-06-27 23:24:06 +08:00
parent e772bd0baf
commit 67dc640c26

View File

@ -34,15 +34,19 @@ MainWindow::MainWindow(QWidget *parent)
ui->actionSave->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S)); ui->actionSave->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
// 添加 "Convert" 菜单 // 添加 "Convert" 菜单
QMenu* convertMenu = menuBar()->addMenu(tr("Convert")); QMenu* convertMenu = menuBar()->addMenu(tr("转换(&C)"));
// 添加 "Text to SQLite" 子菜单项,并关联槽函数 // 添加 "Text to SQLite" 子菜单项,并关联槽函数
QAction* textToSqliteAction = convertMenu->addAction(tr("Text to SQLite")); QAction* textToSqliteAction = convertMenu->addAction(tr("txt 转 SQLite"));
connect(textToSqliteAction, &QAction::triggered, this, &MainWindow::convertTextToSqlite); connect(textToSqliteAction, &QAction::triggered, this, &MainWindow::convertTextToSqlite);
// 添加 "SQLite to Text" 子菜单项,并关联槽函数 // 添加 "SQLite to Text" 子菜单项,并关联槽函数
QAction* sqliteToTextAction = convertMenu->addAction(tr("SQLite to Text")); QAction* sqliteToTextAction = convertMenu->addAction(tr("SQLite 转 txt"));
connect(sqliteToTextAction, &QAction::triggered, this, &MainWindow::convertSqliteToText); connect(sqliteToTextAction, &QAction::triggered, this, &MainWindow::convertSqliteToText);
QIcon convertIcon = QApplication::style()->standardIcon(QStyle::SP_ArrowRight);
textToSqliteAction->setIcon(convertIcon);
sqliteToTextAction->setIcon(convertIcon);
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
@ -259,6 +263,13 @@ void MainWindow::convertTextToSqlite()
{ {
QString line = textStream.readLine(); QString line = textStream.readLine();
QStringList values = line.split("\t"); QStringList values = line.split("\t");
// 截断行内容,保证不超过列名的个数
if (values.size() > columnNames.size())
{
values = values.mid(0, columnNames.size());
}
data.append(values); data.append(values);
} }