Created
June 19, 2017 09:54
-
-
Save jniemann66/8f8abf1483766cccdd8beb78fadff795 to your computer and use it in GitHub Desktop.
Qt Insert row into SQL table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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