Skip to content

Instantly share code, notes, and snippets.

@jniemann66
Created June 19, 2017 09:54
Show Gist options
  • Save jniemann66/8f8abf1483766cccdd8beb78fadff795 to your computer and use it in GitHub Desktop.
Save jniemann66/8f8abf1483766cccdd8beb78fadff795 to your computer and use it in GitHub Desktop.
Qt Insert row into SQL table
#include <QMap>
#include <QList>
#include <QStringList>
#include <QDebug>
// just one way of doing it ...
void MainWindow::on_pushButton_clicked()
{
QMap<QString,QString> data = {
{"fruit","apple"},
{"color","red"},
{"shape","round"}
};
QString columnNames = QStringList(data.keys()).join(",");
QString values = "'" + QStringList(data.values()).join("','") + "'";
QString sqlCommand = "INSERT INTO sometable (" + columnNames + ") VALUES (" + values + ");";
qDebug() << sqlCommand;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment